ASP.NET 500 Internal Server Error while calling webmethod from javascript

前端 未结 5 2085
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-02 17:53

I\'m trying to call the webmethod fucntionality using AJAX but unable to get the appropriate results. I have googled my problem and found many solution but thos

5条回答
  •  無奈伤痛
    2021-01-02 18:27

    First, it the webmethod is in the page class, and not in a Webservice class, then it should be static.

    Second, the data transfered is not really a string, but an object, so change it to:

    var dataString = { 'value':  value  };
    

    Third thing, "type" is for older versions of jquery, you should either change your ajax call to:

    method: "GET",
    url: pagePath,
    data: dataString,
    contentType: "application/json; charset=utf-8",
    dataType: "json",...
    

    Or change the function in the server side to get post calls, by removing the

    UseHttpGet = true
    

提交回复
热议问题