I have PHP code snippet the following:
if (!($result = mysql_query($query, $link))) {
die("Invalid SQL query: " . $query);
}
And I have JQuery code snippet the following:
$.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 to have the die call trigger JQuery error function callback? If not, how would I trigger it otherwise?
Whenever an Ajax request completes with an error, jQuery triggers the ajaxError event. Any and all handlers that have been registered with the .ajaxError() method are executed at this time. Note: This handler is not called for cross-domain script and cross-domain JSONP requests.
If you want to manually trigger the error callback based on the value of the received data you can do so quite simple. Just change the anonymous callback for error to named function. @dallin because it allows you to not duplicate code. The server might respond with code 200 which triggers the "success" callback.
ajax({ url, data: data, type: "POST", dataType: "json", success: function(cbdata) { update_table(cbdata); } }); } $('#selector'). on('click', changeDate); So you can call changeData() when you need it.
jQuery - ajaxSuccess( callback ) Method The ajaxSuccess( callback ) method attaches a function to be executed whenever an AJAX request completes successfully. This is an Ajax Event.
Try this:
if (!($result = mysql_query($query, $link))) {
header("HTTP/1.1 404 Not Found");
}
Choose the error appropriate for your application
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With