Hello I've got a strange problem with an AJAX call on my site. I make a simple AJAX call to a script on my site. But the AJAX call fails with readyState = 4 and status = 0. There's no cross domain problem because the script I want to call is on my server.
$.ajax({
type:"GET",
url: 'http://mydomain.com/test.php',
success : function(response){
console.log(response);
},
error : function(XHR){
console.log(arguments);
}
});
I've googled a lot of sites but there seems to be no solution for that!
This happens when the URL of the AJAX request has a different domain than the page the script is running in. For example, www.mydomain.com
and mydomain.com
are different.
To fix it, replace
url: 'http://mydomain.com/test.php',
with
url: 'http://' + document.domain + '/test.php',
I found this question while looking for the answer myself. I got the solution from here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With