JD. JD. - 9 days ago 7
HTML Question

Why does ajax request with www work?

I have the following code:

$.ajax({
url: frametarget,
dataType: 'html',
method: 'GET',
success: function(data){
// $("#result").html(data[0].title);
console.log(data);
},
error: function(error){
console.log(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.

Answer

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.

Comments