I am trying to send all gridview records to webmethod using jquery ajax but it is not working. Here is my code
function Save() {
var TableData = new Array();
$('[id*=GridView1] tr').each(function (row, tr) {
TableData[row] = {
"Sr" : $(tr).find('td:eq(0)').text()
, "RollNo": $(tr).find('.RollNo').val()
, "Name" : $(tr).find('.Name').val()
, "Marks" : $(tr).find('.Marks').val()
}
});
TableData.shift();
$.ajax({
type: "POST",
url: "TestPage.aspx/SaveData",
data: "{Data:'" + JSON.stringify(TableData) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
}
});
return false;
}
and Code Behind
[WebMethod]
public static string SaveData(List<string> Data)
{
//My Code
return "Success";
}
Help me guys....
webmethod
?? Did you debug? – Guruprasad Rao Oct 8 '15 at 7:39dataType: "json",
and you are not returning back a json response. so i can suggest you to remove it or change it todataType: "text",
– Jai Oct 8 '15 at 7:44TableData.shift();
? – Jai Oct 8 '15 at 7:45