Home  >  Article  >  Web Front-end  >  Detailed introduction to AJAX cross-domain requests

Detailed introduction to AJAX cross-domain requests

零下一度
零下一度Original
2017-07-20 13:14:031411browse

Due to the browser's same-origin policy ajax request cannot receive the data returned from the request response

The request data needs to call the browser's built-in constructor XMLHttpRequest() to obtain the instance object

var xhr = new XMLHttpRequest();

Pay attention to the ActiveXobject ("Microsoft. The object is acquired

The four states of obtaining data xhr.readyState This attribute saves the several states of request data

1.xhr.open (request method, request address, settings are the same as / Asynchronous);

  2.

# 4. Data is returned. Then the value of xhr.readyState is 4, indicating that the data is returned successfully.

So we need to make a cross-domain request, how to do it

Option 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