admin管理员组文章数量:1296485
I am trying to call a web method through ajax call.
The jQuery code is :
$.ajax({
method: "POST",
url: "Login.aspx/LoginMethod",
data: { paramtr: "abc" },
contentType: "application/json; charset=utf-8",
dataType:'json',
success: function (result) {
swal("Done", "User added !", "success");
alert(result);
},
error: function () {
alert('0');
swal("Oops!", "Something went wrong!", "error")
}
});
and the web method code is:
[System.Web.Services.WebMethod]
[ScriptMethod(UseHttpGet = false)]
public static string LoginMethod(string param)
{
string _param = param;
return "OKDONNE";
}
But I am getting Error 500 Internal server error and error function in ajax call gets called alerting '0'.Please help I have tried nearly everything!
I am trying to call a web method through ajax call.
The jQuery code is :
$.ajax({
method: "POST",
url: "Login.aspx/LoginMethod",
data: { paramtr: "abc" },
contentType: "application/json; charset=utf-8",
dataType:'json',
success: function (result) {
swal("Done", "User added !", "success");
alert(result);
},
error: function () {
alert('0');
swal("Oops!", "Something went wrong!", "error")
}
});
and the web method code is:
[System.Web.Services.WebMethod]
[ScriptMethod(UseHttpGet = false)]
public static string LoginMethod(string param)
{
string _param = param;
return "OKDONNE";
}
But I am getting Error 500 Internal server error and error function in ajax call gets called alerting '0'.Please help I have tried nearly everything!
Share Improve this question asked Jul 21, 2016 at 8:37 psyborg.ethpsyborg.eth 3201 gold badge5 silver badges18 bronze badges 2- Is asp able to build a parameter list? I think, LoginMethod can't have any arguments. You have to get the parameters elsewhere. – Holger Commented Jul 21, 2016 at 9:43
- LoginMethod can take parameters . – psyborg.eth Commented Jul 21, 2016 at 9:49
3 Answers
Reset to default 3change this line data: { paramtr: "abc" },
to data: { param: "abc" },
.
Because your c# code accepts param
not paramtr
.
I solved the issue by putting the following line of code :
data: JSON.stringify({ param: 1}),
Now everything is working fine without errors . Thanks to @vivek for his inputs
Always ensure your json key is the same as the parameters received by the web method. e.g...
var obj = new Object();
obj.id = 'person';
obj.age = 30;
[WebMethod]
public static string savePerson(string id, int age){
string oute = "";
return oute;
}
I figured out after almost a day of error 500
本文标签: javascriptAjax call to webmethod gives ERROR 500 Internal server errorStack Overflow
版权声明:本文标题:javascript - Ajax call to webmethod gives ERROR 500 Internal server error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741639345a2389826.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论