tags:

views:

34

answers:

2

Hello all,

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

+3  A: 

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

Dutchie432
Thank you very much
q0987
+4  A: 

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’);
Nikolaus Gradwohl
This is pretty much the same thing I suggested. I suggested pointing to an invalid URL and you suggested "faking" an invalid URL. I guess it's just a matter of which file you want to edit :) Good, clean solution.
Dutchie432
you have more control over the type of error you want to simulate this way
Nikolaus Gradwohl
You're absolutely correct. I still say, for the purposes of this post, it's apples and apples.
Dutchie432