406 Error when returning JSON object – Unexpected content

A few colleagues and I have a problem whereby the response from an ajax call returns some unexpected content. Rather than getting a simple JSON object back with various properties, the value of result.responseText is the HTML markup of a generic 406 status error page, saying the MIME type is not accepted by the browser.

The call is made like so:

$.ajax({
    url: '/promociones/cincogratis/canjear-codigo-promocional',
    type: this.method,
    data: $(this).serialize(),
    success: function (result) {
           $('.promotion_banner .loader').hide();
           $('.promotion_banner').html(result);
    },
    error: function (result) {
           var obj = result.responseText;
           if (obj.isRedirect) {
                   document.location = obj.redirectUrl;  
           }
           else {
                   $('.promotion_banner .loader').hide();
                   $(".error-wrapper").removeClass("hidden");                           
                   var generic_error = document.getElementById('generic_error').value;
                   $(".error-wrapper p").html(generic_error);
           }
    },
    beforeSend: function() {
           $('.promotion_banner .loader').show();
    }
});

The controller response to the call is like so:

Response.StatusCode = (int)HttpStatusCode.NotAcceptable; // 406
return Json(new { errorMessage = LocalErrorMessages.Website_Promotions_FreeFiver_General_Problem, isRedirect = false } );

We would expect result.responseText to contain key values for errorMessage and isRedirect, but they’re not there.

It’s worth pointing out that this code is multi-tenanted, shared by the current application and another one, where it works absolutely fine.

We’ve tried: - Configuring IIS to show detailed error responses rather than a custom page for more detail – gives us nothing extra towards solving the problem. - Allowing all response content types to the call - Changing the culture of our site (which is currently es-ES) - Various web.config tweaks

Has anyone ever had this problem?

Answers


Simplify your request. Maybe something like:

$.ajax({
    url: '/promociones/cincogratis/canjear-codigo-promocional',
    type: 'GET',
    data: {foo:'bar', one:'two'},
    dataType: 'json',
    success: function (result) {
           console.dir(result);
    },
    error: function (xhr) {
           console.dir(xhr)
    }
});

And post the response from the server. This kind of error seems a request problem rather than server configuration issue


Need Your Help

Anconda 1.9.1 installation related help required

python python-3.x anaconda conda

I installed Anconda 1.9.1 and Minicoda3 twice on my windows 7 machine. Every time, after installation, I tried to use command conda info or try to create environment using conda, I get this message:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.