0

I am doing simple save operation (Code is as per tutorial)
...but ajax is not sending json data to save method

on Firebug console it displays following Error:

"NetworkError: 500 Internal Server Error - http://localhost/WebApplication2/WebForm1.aspx/saveData"

(Note: My libraries are updated and properly placed.)

ajax

    var name = "neeraj";
    var gender = "male";

    $.ajax({
        type: "POST",
        url: "WebForm1.aspx/saveData",
        data: { 'name': JSON.stringify(name), 'Gender': JSON.stringify(gender) },
        contentType: "application/json;charset=utf-8",
        dataType: "JSON",
        async: "true",
        success: function (response) {
            alert('success');
        }
    });

My page url is

  ../WebApplication2/WebForm1.aspx

save method(webform1.aspx.cs)

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static int saveData(string name, string Gender) 
{ return 1;}

Similar Posts:

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3487944
  • 267
  • 4
  • 9
  • 22

1 Answers1

1

finally it is Redirecting .. i was too close ...

instead of

data: { 'name': JSON.stringify(name), 'Gender': JSON.stringify(gender) },

Just need to change to

data: JSON.stringify({ 'name': name, 'Gender': gender }),

this post helped

jQuery AJAX call to an ASP.NET WebMethod

Community
  • 1
  • 1
user3487944
  • 267
  • 4
  • 9
  • 22