0
  //c# method
  [WebMethod]
     public static string HelloAction(string value)
     {
          Client clt = new Client();
          clt.name = "Hello "+value;

          return JsonConvert.SerializeObject(clt);
     }

// Javascript code

var nameJson= {
         "name" : "William"
    };

    $.ajax({
        type: "POST",
        data: JSON.stringify({ 'name': nameJson }), // ??
        url: "Index.aspx/HelloAction",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: successHello
    });

But chrome console show this error: POST http://localhost:9252/Index.aspx/HelloAction 500 (Internal Server Error)

6
  • Do you have custom errors turned off? What is the stack looking like? How about routing? Have you setup route mapping anywhere? Commented Apr 16, 2017 at 20:11
  • The file path is fine, since invoking a method with no input parameters this returns me values ​​without problem, but when I want to send parameters to the method, there the system falls Commented Apr 16, 2017 at 20:44
  • You're going to have to expose the exceptions so we can see if it's a binding issue or what. I don't see any issue with your method. Commented Apr 16, 2017 at 20:51
  • Try stringifying this object: { name: nameJson } instead of { 'name': nameJson }. Let me know if that works. Commented Apr 16, 2017 at 21:07
  • Actually just stringify. nameJson You're double wrapping like this as it stands: { 'name' : { 'name' : 'william' } } which will not work out properly. Unless that's a typo. Didn't see that at first. Commented Apr 16, 2017 at 21:21

1 Answer 1

1

In your ajax code change the following line

data: JSON.stringify({ 'name': nameJson })

to this one

 data: JSON.stringify(nameJson)
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.