I am doing a little ajax ping-pong and wondering if it is possible to make a pending ajax object fall into a failure state from PHP.
$.ajax({ url: 'example.com/post', dataType: 'json' }) .done(function(data) { console.log(data); }) .fail(function(data) { console.log(data); });
and in php
function post() { if (false) { echo json_encode(array('all good')); } else { ??? } }
You can return the error header:
header('HTTP/1.0 404 Not found'); exit;
This will cause jQuery to start the error handler and, in turn, not migrate Ajax. Basically, status codes like 4xx and 5xx` will do the trick.
4xx
Source: https://habr.com/ru/post/916919/More articles:Mix org-mode and c-mode in emacs - emacsMySQL "SELECT DISTINCT" Efficiency for very large tables - performanceHow to set null in Integer in spring context - javaXcode will not update the application icon. - xcode4How to select nodes by attribute that starts with ... in C # - c #CakePHP and tinyint as logical - phpHow to encrypt ASP.NET 4.0 Web.Config? - asp.netReset iOS simulator between tests - iosKnockout.js: ko.applyBindings (viewModel) -> is there a complete event for applyBinding? - knockout.jsMerging two UIImages faster than CGContextDrawImage - iosAll Articles