How to call a "callback" callback in a jQuery AJAX call using in PHP

I have a PHP code snippet:

if (!($result = mysql_query($query, $link))) { die("Invalid SQL query: " . $query); } 

And I have a jQuery code snippet:

 $.ajax({ url: "....search.php", data: ..., async: false, //to trigger error alert success: function(xml) { ... }, error: function(xml) { foundError = true; }, dataType: "xml" }); if(foundError) { setProgress("Could not complete the search because an error was found", ProgressBar.ERROR); } 

Is it possible for a jQuery call invocation function call to invoke a call? If not, how would I call it otherwise?

+6
source share
3 answers

Try the following:

 if (!($result = mysql_query($query, $link))) { header("HTTP/1.1 404 Not Found"); } 

Choose the error that is appropriate for your application.

+9
source

You cannot signal client code from the server (at least not in the way you expect).

When using AJAX, it is best to use the correct HTTP response codes and use jQuery for those in error: callback.

0
source

You cannot access the ajax error since there was no ajax error. What you can do is check your xml variable in the success section; if it starts with an Invalid SQL query , you know that a php error has occurred.

To remove everything, you probably want to return some more information (xml / json) in case of an error instead of a string.

0
source

Source: https://habr.com/ru/post/892074/


All Articles