Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

safari - jquery - ajax 500 internal server error

Tags:

jquery

asp.net

I have created an jquery ajax call and it is working fine in Chrome, firefox and IE.

Where as in Safari, it is giving 500 internal server error in the response. I though it could be due to an exception from Server. But when i tried debugging, i found that it is not hitting the server at all.

The wierd thing in this is, the ajax-call works for every alternate calls. Call-1 fails and then call 2 succeeds.enter image description hereenter image description here

Am attaching the screen shot of the request and response(both success and error). Please help me to fix this problem.

Thanks in advance, Raghav

var coId = globalObject.GetCompanyIdFromUrl();
if ($("#headerCompanyMenu").length > 0 && coId != "") {
    var strData = "{\"coId\":\"" + coId + "\"}";
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        cache: false,
        url: globalObject.rootPath + "search/webmethod.aspx/GetCoHeaderData",
        data: strData,
        async: true,
        success: function (d) {
            var coHeaderData = JSON.parse(d);
            $("#lblCoNm").html(coHeaderData.lblCoNm);
            $("#lbl_prim_im").html(coHeaderData.lbl_prim_im);
            $("#lbl_prim_md").html(coHeaderData.lbl_prim_md);
            $("#lbl_prd_own").html(coHeaderData.lbl_prd_own);
            $("#lbl_geo_own").html(coHeaderData.lbl_geo_own);
            $("#lbl_org_inv").html(coHeaderData.lbl_org_inv);
            $("#lbl_out_inv").html(coHeaderData.lbl_out_inv);
            $("#lbl_cur_val").html(coHeaderData.lbl_cur_val);
            $("#lbl_nbv").html(coHeaderData.lbl_nbv);
            $("#lbl_fv").html(coHeaderData.lbl_fv);
            $("#lblProc").html(coHeaderData.lblProc);
            $("#lblFinGrd").html(coHeaderData.lblFinGrd);

            if (coHeaderData.addNewDeal == "true")
                $("#lnkAddNewDeal").show();
            if (coHeaderData.coDeals.length > 0) {
                BindData("coDealsTmpl", coHeaderData.coDeals);
                $("#coDeals").show();
            }
        },
        error: function (error) {
            //alert("Company search error");

        }

    });

Am running the safari from Win7. The actual Mac's safari loads it perfectly fine. No errors for ajax call.

The server is windows 2008, running iis 7. No loadbalancing servers. Each time the ajax-call is hitting the same server same method, with same input-data and expects the same output data.

like image 501
Raghav Avatar asked Feb 02 '12 05:02

Raghav


People also ask

What is 500 Internal server error Ajax?

The 500 Internal Server Error is a very general HTTP status code. It means something has gone wrong on the website and webserver is unable to specify what exactly, thus failing in fulfilling the request made by the client. Reload the web page.

How do I fix request failed with status code 500?

Most of the time, the issue is only temporarily and can be corrected by trying the page again. You can use the refresh/reload button, pressing F5 , or by trying the URL again from the address bar. Sometimes this error is caused when a service restarts, and you happen to catch it at exactly the wrong time.


3 Answers

I would say that the reason the call is failing is because of a bug in Safari when working with Windows Authentication under IIS. Go to the Authentication settings of your website. Right click on Windows Authentication, choose providers and remove Negotiate, leaving NTLM which works fine. I haven't tested Kerberos.

This issue only appears in certain builds of safari.

like image 122
Aran Mulholland Avatar answered Oct 17 '22 23:10

Aran Mulholland


First: I would check to make sure that $("#headerCompanyMenu").length > 0 && coId != "" evaluates to true when you think it should be.

Second: I would make sure that you have a '/' at the end of globalObject.rootPath when you are using Safari.

Third: I would change up your ajax post to look like this:

var coId = globalObject.GetCompanyIdFromUrl();
if ($("#headerCompanyMenu").length > 0 && coId != "") {
    var strData = {'coId' : coId};
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        cache: false,
        url: globalObject.rootPath + "search/webmethod.aspx/GetCoHeaderData/",
        data: strData,
        dataType: "json",
        async: true,
        success: function (d) {
            var coHeaderData = JSON.parse(d);
            $("#lblCoNm").html(coHeaderData.lblCoNm);
            $("#lbl_prim_im").html(coHeaderData.lbl_prim_im);
            $("#lbl_prim_md").html(coHeaderData.lbl_prim_md);
            $("#lbl_prd_own").html(coHeaderData.lbl_prd_own);
            $("#lbl_geo_own").html(coHeaderData.lbl_geo_own);
            $("#lbl_org_inv").html(coHeaderData.lbl_org_inv);
            $("#lbl_out_inv").html(coHeaderData.lbl_out_inv);
            $("#lbl_cur_val").html(coHeaderData.lbl_cur_val);
            $("#lbl_nbv").html(coHeaderData.lbl_nbv);
            $("#lbl_fv").html(coHeaderData.lbl_fv);
            $("#lblProc").html(coHeaderData.lblProc);
            $("#lblFinGrd").html(coHeaderData.lblFinGrd);

            if (coHeaderData.addNewDeal == "true")
                $("#lnkAddNewDeal").show();
            if (coHeaderData.coDeals.length > 0) {
                BindData("coDealsTmpl", coHeaderData.coDeals);
                $("#coDeals").show();
            }
        },
        error: function (error) {
            //alert("Company search error");

        }

    });
like image 29
Jason Avatar answered Oct 18 '22 00:10

Jason


In addition to CCCason's comments, I would explicitly tell the ajax call that it's datatype is json by adding:

dataType: "json"

Maybe safari is guessing the wrong data type?

like image 41
ryanulit Avatar answered Oct 18 '22 01:10

ryanulit