JD. JD. - 3 months ago 40
HTML Question

Why does ajax request with www work?

I have the following code:

url: frametarget,
dataType: 'html',
method: 'GET',
success: function(data){
// $("#result").html(data[0].title);
error: function(error){

Now if frametarget = "www.skysports.com" the call is a success but using skysports.com the call fails?

I am making cross domain calls for both URLs, so I expected both to fail.


For http://www.skysports.com cross domain requests are allowed by this response header: Access-Control-Allow-Origin: *.

For http://skysports.com there is no CORS header in the response, therefore the browser denies the request.

See MDN HTTP access control (CORS) for more informations.