If the server has a response header of 'Access-Control-Allow-Origin': '*'
or something similar, it will return a response.
In short, this has nothing to do with jQuery, and has everything to do with the server.
In the case above, *
is a wildcard representing all origins. But it could also specify a list of origins.
Keep in mind, even in CORS requests, you can always send a request to the server, and the server will always receive it. It will only return a response though if it wants to (in this case, with the access control header, it will.)
If the server didn't have that header, then you'll get the common error in the console saying that XMLHTTPRequest could not complete because the server does not allow cross-origin communication
or whatever the heck it says.
It depends on the architecture the server is using, but if it's a Node.js server using Express (for example), you'd see something like this is the server.js
file or wherever:
app.use(function(req, res) { res.header('Access-Control-Allow-Origin', '*') });
The approach would be vastly different on different sever architectures (like Apache), but the header is standardized as part of HTTP, so that part stays the same.
See AJAX Cross Domain for an example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…