1

What would cause the XHR to get overriden? I'm assuming that's what's happening here.

I am setting the status and code, show here, with a helper class:

 if (program.Name == programName)
 {         
    ServiceHelper.SetHttpError(501, "'Program Name' Already Exists.'");
    return;       
 }

class:

public static void SetHttpError(int statusCode, string message)
{
   HttpContext.Current.Response.StatusCode = statusCode;
   HttpContext.Current.Response.StatusDescription = message;
}

handling the xhr:

function CallService(method, jsonParameters, successCallback, errorCallback) 
        {
            if (errorCallback == undefined) 
            {
                errorCallback = function(xhr) {
                    if (xhr.status == 501) {
                        alert(xhr.statusText);
                    }
                    else {
                        alert("Unexpected Error");
                    }
                }
            }            

            $.ajax({
                type: "POST",
                url: method,
                data: jsonParameters,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: successCallback,
                error: errorCallback
            });
        }

At one time this was working.. now all that the alert shows is "error" not the message I'm providing..

Any idea?

Avien
  • 1,270
  • 2
  • 14
  • 30

2 Answers2

1

What version of jQuery are you using? The latest docs say that the signature of the error callback is:

error(jqXHR, textStatus, errorThrown)

Your message might be in the textStatus argument.

Have you tried using FireBug to break on the error function and look at the properties of the xhr object?

Sergi Papaseit
  • 15,999
  • 16
  • 67
  • 101
  • you are correct.. I just figured this out. Wish I would have checked back here a couple hours ago.. At first I thought it was an issue with IIS/Cassini. I didn't realize they changed the signature with jquery 1.5. – Avien Apr 07 '11 at 15:45
0

I came just accross a similar issue where this statusText was not set, but only when using HTTPS on IIS, whereas it would work on on plain HTTP. I eventually found that IIS only supports HTTP2 on TLS, and in HTTP2 there is no status code description anymore. When I used Fiddler to troubleshoot, it worked in both http and https, probably because of this !

In ASP.NET MVC you just can't use HttpStatusCode(code,description) anymore because the description will go nowhere. You have to pass the description e.g. into the response body instead. Or disable HTTP2 for the time being.

Vincent67
  • 11
  • 3