Flawless
Flawless

Reputation: 11

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Currently im doing an asp.net website where im trying to get data from the webservice and display the data retrieved to the table. Below is the ajax.

<script type="text/javascript">
$.ajax({
type: "GET",
url: "/CaregiverService.asmx/createJsDataTable",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (json) {
    console.log(json);
    console.log(json.d.aaData);
    $('#nursingHomeTable').dataTable({
        "aaData": json.d.aaData,
    });
},
error: function(XMLHttpRequest, textStatus, errorThrown) { 
                alert("Status: " + textStatus); alert("Error: " + errorThrown); 
            }    
});
</script>

For the webservice

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public JsonDataTable createJsDataTable()
        {

        JsonDataTable jsDT = new JsonDataTable();

        List<object> vl = new List<object>();
        vl.Add("value 1");
        vl.Add("value 2");
        vl.Add("value 3");
        vl.Add("value 4");
        jsDT.add_Row(vl);

        return jsDT;
       }

Have been getting that error when i inspect the element but still dont get wheres the error. I have clicked the http://localhost:2179/CaregiverService.asmx/createJsDataTable from the inspect element in google chrome and it works fine. Hoping someone could help me solve it :x

Upvotes: 1

Views: 9589

Answers (1)

Alexander Ryan Baggett
Alexander Ryan Baggett

Reputation: 2397

I don't know if this will fix your problem or not, but I was pretty sure that Asp.net webservices take only from the POST Method by default. So try changing type to POST.

OR

Set try setting this up in your receiving end in the webservice

[WebMethod]
[ScriptMethod(UseHttpGet = true)]

OR

in your web.config try this

<webServices>
    <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
    </protocols>
</webServices>

Upvotes: 0

Related Questions