Shivank Verma Shivank Verma - 2 years ago 67
Ajax Question

Ajax call to webmethod gives ERROR 500 Internal server error

I am trying to call a web method through ajax call.

The jQuery code is :

method: "POST",
url: "Login.aspx/LoginMethod",
data: { paramtr: "abc" },
contentType: "application/json; charset=utf-8",
success: function (result) {
swal("Done", "User added !", "success");
error: function () {
swal("Oops!", "Something went wrong!", "error")

and the web method code is:

[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!

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download