0

I'm trying to make a really simple ajax request in jQuery from http://dev.example.com/shop/category which looks like this:

$.post("http://dev.example.com/ajax/test.php", function(data) {
    alert("loaded");
});

No response is returned and Firebug's Status field is blank. Chrome says "(canceled)".

The test.php works fine when I open it in the browser.

It's on the same domain so I don't think it's a cross-site issue (I've tried a relative path too).

Any ideas?

WackGet
  • 2,667
  • 3
  • 36
  • 50
  • 1
    Opening in the browser will make a GET request, but here you are making a POST request, are you sure you want the latter? – Cole Pilegard Aug 29 '13 at 17:39
  • Where is this code being called? Maybe a link being clicked? http://stackoverflow.com/questions/7577275/jquery-ajax-requests-are-getting-cancelled-without-being-sent – Ian Aug 29 '13 at 17:39
  • Try using the `$.ajax()` structure instead (`$.post()` is the same command, just with `type="POST"` hard-coded). [See this post](http://stackoverflow.com/questions/17973386/ajax-request-callback-using-jquery/17974843#17974843) for simple examples of how it should work. – cssyphus Aug 29 '13 at 17:46

1 Answers1

1

It was because my script was doing something else without waiting for the result of the ajax request. I just used $.ajax with async:false and it worked! Thanks to everyone who commented.

WackGet
  • 2,667
  • 3
  • 36
  • 50