Hi,
This is regarding your article on
http://www.aspsnippets.com/Articles/Send-and-Receive-JSON-objects-to-Web-Service-Methods-using-jQuery-AJAX-in-ASPNet.aspx#comments
I have a json object with multiple Name & Value pairs, I am using example on above given link but it is not calling the Web Method.
var jd = [];
jd.push({ ID: HArr[j], Val: Str });
var jd = [];
for (var i = 0; i < jsonData.length / Tcnt; i++) {
var ctrl;
for (var j = 0; j < Tcnt; j++) {
ctrl = (parseInt(i) * parseInt(Tcnt)) + parseInt(j);
Str = jsonData[ctrl];
jd.push({ ID: HArr[j], Val: Str }); //Pushing values to Json Array
}
}
$.ajax({
type: 'POST',
url: 'PageName.aspx/PassJsonData',
data: "{jd:" + JSON.stringify(jd) + "}",
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function(r) {
alert(r.d.ID);
alert(r.d.Val);
},
failure: function(response) {
alert(response.d);
}
});
In code behind I have created a class with two attributes ID and Val.
public class jsonData
{
private string id;
public string ID{get{return id;}set{id = value;}}
private string val;
public string Val { get { return val; } set { val = value; } }
}
In my class I have a Web Method defined as :
[System.Web.Services.WebMethod]
public static jsonData PassJsonData(jsonData jd)
{
return jd;
}