1

I have a piece of code:

$.get("go.php?action=sliderorder&right=5")
.success(function(data){alert("success!");})
.fail(function(data){alert("failed!");});

The output of the ajax call is "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near..."

The alert i'm getting is still "success!" although clearly the ajax failed.
So my question is: how do jquery address failed ajax calls?

Thanks ahead.

Nir Tzezana
  • 2,275
  • 3
  • 33
  • 56
  • Check your backend code in `go.php`. What are you returning when an exception is thrown? Do you ever return a failure? – Meredith Aug 11 '13 at 21:44
  • I take this as a failure, when MySQL returns an error – Nir Tzezana Aug 11 '13 at 21:49
  • "The alert i'm getting is still "success!" although clearly the ajax failed." I mean returning a 5xx HTTP status code when I say "return a failure". @zerkms 's got you covered. – Meredith Aug 11 '13 at 21:53

1 Answers1

2

It determines if the error occurred by HTTP status code. The 4xx and 5xx codes is what you're after.

But, you generally should NEVER get "You have an error in your SQL syntax; check the manual that corresponds " error. Without exceptions - this should NEVER occur in your production code. If it does - you immediately should find the roots of the issue.

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • Ok that's a start, is there a way for PHP to tell the page it failed in doing what it should have been doing? such as "die()"? – Nir Tzezana Aug 11 '13 at 21:44
  • Is there a way to combine with an "mysql_query("") or die()" ? – Nir Tzezana Aug 11 '13 at 21:49
  • 1
    @Nir Tzezana: `$result = mysql_query(...); if (!$result) {}`. But normally your `mysql_query` shouldn't fail, at least with syntactic error reason. I would say you need to fix your code, because it looks like it's broken – zerkms Aug 11 '13 at 21:50