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