Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my $.ajax request always fail?

Tags:

jquery

This is how I use $.ajax

var link = "http://www.myapp.net/..."

$.ajax({
    url: link,
    cache: false,
    async: false,
    success: function(html){

    },
    error: function(){

    }
});

The result of the request is either an empty page or a page with just a number. So error callback actually should never be triggered, as long as the request does not fail.

But I always get the following error

alert(jqXHR + "-" + textStatus + "-" + errorThrown);

enter image description here

Here is some information about the error code in the picture

I run my project on localhost. The link in the ajax code points to another project on the web.

Any ideas?

like image 954
UpCat Avatar asked Mar 06 '26 05:03

UpCat


1 Answers

The error callback is executed if the ajax call can't be completed - i.e. if the url is on a different domain (or if you are running it from a local file), if the request timeouts, or if the server responds with an error code.

I'm guessing it's a domain (same-origin) policy error

Update: If you want to do cross-domain Ajax, check out James Padolsey's jQuery snippet for just that (uses Yahoo!s public proxy to make all jQuery Ajax calls cross-domain)

like image 58
Jens Roland Avatar answered Mar 07 '26 22:03

Jens Roland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!