Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - How to simulate an error event for ajaxSubmit

Tags:

jquery

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, // 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

like image 523
q0987 Avatar asked Aug 24 '10 12:08

q0987


2 Answers

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’);
like image 92
Nikolaus Gradwohl Avatar answered Sep 29 '22 03:09

Nikolaus Gradwohl


.....try pointing the AJAX Request to an invalid URL? I think that'll work..

like image 23
Dutchie432 Avatar answered Sep 29 '22 03:09

Dutchie432