How to make an AJAX call using JavaScript, without using jQuery?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- Carriage Return (ASCII chr 13) is missing from tex
- void before promise syntax
- Keeping track of variable instances
Here's a JSFiffle without JQuery
http://jsfiddle.net/rimian/jurwre07/
http://ajaxpatterns.org/XMLHttpRequest_Call
You can get the correct object according to the browser with
With the correct object, a GET might can be abstracted to:
And a POST to:
You can use the following function:
You can try similar solutions online on these links:
With "vanilla" JavaScript:
With jQuery:
I hope it helps
Step 1.
Store the reference to the XMLHttpRequest objectStep 2.
Retrieve the XMLHttpRequest objectStep 3.
Make asynchronous HTTP request using the XMLHttpRequest objectStep 4.
Executed automatically when a message is received from the server