"Is it a non-200 status code"

I can't say it's 100% of the time, but in my code it seems to be the
case

this code:

function reqJSON(url, params, success, error) {
    var CallParams = {};
    CallParams.type = params.Method || "POST";
    CallParams.url = url;
    CallParams.processData = true;
    CallParams.data = params;
    CallParams.dataType = "json";
    CallParams.success = success;
    if (error) {
        CallParams.error = error;
    }
    $.ajax(CallParams);
}

goes into the error event if a 500 status code is encountered during
the process








On Dec 17, 9:36 am, "Andy Matthews" <li...@commadelimited.com> wrote:
> I think the problem is that you're expecting a different sort of error than
> what the AJAX call is expecting. That method only looks for an error in what
> it's trying to do. The server process is solely separated from the JS
> process.
>
> You could check for a string of "error" on success, then pass that over to
> an error method.
>
> andy
>
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
>
> Behalf Of Rob Wilkerson
> Sent: Wednesday, December 17, 2008 8:26 AM
> To: jQuery (English)
> Subject: [jQuery] HowTo: Trigger error callback in ajax request
>
> I have an ajax request being sent to a PHP script. If that script captures
> an error, I'd like it to echo that error and return whatever it needs to
> return to trigger the error callback in my ajax call. I can't seem to find
> what that is.  Is it a non-200 status code?  Simply throwing an error (throw
> new Exception()) just triggers the success callback with the error text (not
> unexpectedly, of course).
>
> I'm using the jQuery form plugin and using the .ajaxSubmit() method, but I
> suspect the answer would be the same for a core .ajax() call.
> My simplified case looks like this:
>
> $(document).ready ( function() {
>         $( '#CommercialVendorAddForm' ).submit (
>                 function() {
>                         $(this).block();
>
>                         $(this).ajaxSubmit ({
>                                 beforeSubmit: function() {
>                                         alert ( 'validating' );
>                                 },
>                                 success: function ( responseText,
> responseCode ) {
>                                         alert ( 'success' );
>                                         alert ( responseText );
>                                 },
>                                 error: function() {
>                                         alert ( 'An error has occured. Your
> application could not be submitted.' );
>                                 },
>                                 complete: function() {
>                                         $( '#CommercialVendorAddForm'
> ).unblock();
>                                 }
>                         });
>
>                         return false;
>                 }
>         );
> });
>
> I can't believe that there's not a way to force the error callback to
> receive the response if the server page returns an error, but what is that
> way?
>
> Thanks.
>
> Rob

Reply via email to