我似乎无法让这个 ajax 调用工作。我有这块javascipt:
function exportCSV(e) {
var data = document.getElementById("mainTable").innerHTML;
$.ajax({
url: "Handlers/Handler.ashx/saveToCsv",
type: "POST",
contentType: 'application/json; charset=utf-8',
//data: data,
success: function (msg) {
alert("Success");
alert(msg);
},
error: function (msg) {
alert("failed ");
}
});
}
然后我有一个 handler.cs 文件,我试图调用这个方法:
[WebMethod]
public static string void saveToCsv()
{
StringBuilder sb = new StringBuilder();
//yet to implement rest
return "hello";
}
但是我似乎无法弄清楚为什么它一直失败。