DarkLeafyGreen
DarkLeafyGreen

Reputation: 70466

Why does my $.ajax request always fail?

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?

Upvotes: 3

Views: 4373

Answers (1)

Jens Roland
Jens Roland

Reputation: 27770

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)

Upvotes: 5

Related Questions