This time I will bring you a summary of AJAX cross-domain request data methods (practical explanation), what are the precautions for AJAX cross-domain request data, the following is a practical case, let's take a look.
Due to the browser's same-origin policy, ajax requests cannot receive data returned from the request response
The request data needs to call the browser's built-in constructor XMLHttpRequest() Instance object
var xhr = new XMLHttpRequest();
Note that ActiveXobject("Microsoft. Wrote
Get through this object
Four states of obtaining data xhr.readyState This attribute saves several states of request data
1.xhr.open(request method, request address, set synchronous/asynchronous);
2.xhr.send(null);// Send request If it is a post request then the parameters need to be passed in send
3. It will always check whether the data is returned
4. When data is returned, the value of xhr.readyState is 4, indicating that the data is returned successfully.
So how do we make a cross-domain request?
Solution 1:
Use the src attribute of the script tag to request data. The data requested by the src attribute will not be intercepted by the browser.