cagin cagin - 2 years ago 72
Javascript Question

jQuery ajax call doesn't work with parameters

I want to call a web service method. here is my jQuery code:

var name = $("#Name").val();
type: "POST",
url: "CityList.aspx/Edit",
data: '{"name":' + name + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {

error: function (msg) {

And here is my server side code:

public static void Edit(string name)

When I pass the parameter, it is falling to error but I call the method without parameter everything is ok. Do you have any suggestions?

Answer Source

I changed my data text with: data: '{name:"' + name + '",id:' + id + '}' and it resolved. Thanks for you helps.

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