Oh, and to answer "how do I trigger the error function?"
You don't. The error callback is triggered automatically if the script
times out, or a 404 status is returned, or your response data does not
match your dataType, etc. Your focus is to get the user to not get to
this 'error' callback, but it's more of a catch for uncontrollable
failures (eg. network issues).

On Feb 26, 4:30 pm, James <[email protected]> wrote:
> A success status is whatever HTTP 200 status plus a valid dataType
> that you specified as the response.
> You can use PHP to echo back JSON like:
>
> $error = 1
> $json = array('error' => $error, 'text' => 'hello world!');
> echo json_encode($json);
> exit;
>
> Then in your AJAX success callback:
> success: function(data) {
>      if (data.error == '1') alert('failed');
>      else alert(data.text);
>
> }
>
> Remember to set your dataType to 'json' in your AJAX options.
>
> On Feb 26, 4:18 pm, Gelegrodan <[email protected]> wrote:
>
> > Hello
> > I use the validation plugin and the following code:
>
> >                 submitHandler: function(form) {
> >                         $('#submit').attr("disabled", "true");
> >                         $.ajax({
> >                                 type: 'POST',
> >                                 url: 'submit.php',
> >                                 data: $('#registerform').serialize(),
>
> >                                 error: function() {
> >                                         $('#mess').html("Failure");
> >                                         $('#mess').css("display", "block");
> >                                         alert('Fail!');
> >                                 },
> >                                 success: function(responseText) {
> >                                         $('#mess').html("True");
> >                                         $('#mess').css("display", "block");
> >                                         alert(responseText);
> >                 }
> >                         });
> >                 }
>
> > submit.php is php script which checks the inputs for errors, but what
> > shall my php-script response if there is something wrong?
> > And can I have a "responsetext" with it? (like on success)
>
> > So the question is: who do I trigger the error function?
>
>

Reply via email to