jQuery - How to simulate an error event for ajaxSubmit
I use the ajaxSubmit to submit my form and would like to test the case where the event returns error.
var options = {
beforeSubmit: showRequest, // pre-submit callback
success: showResponse, 开发者_JAVA技巧// post-submit callback
error: printError,
url: '../validation.php'
};
$('#form1').submit(function () {
$(this).ajaxSubmit(options);
return false;
});
In other words, I need to know how to simulate an error event so that I can test the function printError.
Thank you
return an errorcode from your php script using the header statement. For example
header(‘HTTP/1.0 403 Forbidden’);
or
header(‘HTTP/1.0 404 Not found’);
.....try pointing the AJAX Request to an invalid URL? I think that'll work..
You can use Fiddler's autoresponder feature to intercept XHRs and simulate various error responses. This is especially helpful if you do not want to (or cannot) to meddle with server side code.
精彩评论