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:

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.