I'm encountering Error 500 Internal Error while Posting Handsontable Data into ASP.NET Code Behind function using Ajax. I don't understand where I'm going wrong. Please Help.
My Ajax Code:
function SaveData() {
// Check What's Getting Updated
for(var i in changedData){
console.log(changedData[i]);
}
// Ajax Call
$.ajax({
type: "POST",
url: "StudentHandsOn.aspx/SaveData",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(changedData),
success: function (changes) {
console.log('Data Updated: '+changedData);
},
error: function (thrownError) {
alert("Error" + thrownError);
}
});
}
And My C# CodeBehind is:
[WebMethod]
public static void SaveData(List<Student> students)
{
StudentHandsOn handsOn = new StudentHandsOn();
handsOn.displayMessage();
}
public void displayMessage()
{
Response.Write("<script>alert('Function Called.... Working Fine ');</script>");
}
I've Checked For What's There in the ChangedData Array Using the for Loop in SaveData and is running fine.
["st_01", "Albert ", 3, "CE ", "Angela ", 70, 90, 90, 250, 83.33333333333333, "B "] StudentHandsOn.aspx:218
["st_02", "Inger ", 2, "CE ", "Angela ", 67, 98, 99, 264, 88, "B "] StudentHandsOn.aspx:218
POST http://localhost:53600/StudentHandsOn.aspx/SaveData 500 (Internal Server Error)
Update:
I've added a few lines to my code:
var studentData = JSON.stringify(changedData) ;
console.log(studentData);
And Changed the Parameter type in SaveData method to List. I'm getting Output in the console as.
[["st_01","Albert ",3,"CE ","Angela ",70,90,90,250,83.33333333333333,"B "],["st_02","Inger ",2,"CE ","Angela ",67,98,99,264,88,"B "],["st_03","Hamlet ",1,"EE ","Emily ",60,60,60,180,60,"D "],["st_04","Jiny ",4,"CS ","Vannila ",100,80,70,250,83.33333333333333,"B "]] StudentHandsOn.aspx:218
POST http://localhost:53600/StudentHandsOn.aspx/SaveData 500 (Internal Server Error)
I'm getting an array of arrays now. How do I pass this tothe code behind method?
尝试将序列化数据代码更改为:
data: '{"students": "' + JSON.stringify(changedData) + '"}',
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.