[jQuery] Delibarately create ajax errors from PHP script

[jQuery] Delibarately create ajax errors from PHP script


Sorry if this has been posted before but I searched the group and
could not find a clue.
I have a problem which I believe has a simple solution but could not
come up with a good way.
While using Jquery with PHP, I want error checking to be implemented
on the server side - with PHP. As it's much safer and also easier for
me. All of the articles/tutorials I've seen about Jquery uses client
side Javascript.
Whilst I have no problems doing this with PHP , if the server side
validation fails [ex: missing a required field or an out of range
value in a form etc] I would like the results of this to be printed as
a result of errror: section.
A typical ajax request is :
$.ajax({
    type: "POST",
    url: "script.php",
    data: {
        ...........
    },
    success:
        function(t) {
        .... show the result of successful ajax call
        },
    error:
        function() {
        .... show the result of a failure : server timeout etc.
        }
});
}
If the validation fails I would like to output the error messages as a
result of the error: section because on the success part I usually
hide/fadeout the form elements. But as the PHP script has been
completed successfully output of the php falls to success section
I try to overcome this problem by attaching another event to the
output of script, ie: document.ready.function( .....
but this is really cumbersome.
I would highly appreciate other people's solutions, ideas on this
subejct
Irfan