我有一个aspx页面。我想通过jquery调用ASP.NET方法。我已经实现了代码,但问题是我得到整个页面的HTML而不是从ASP方法获取返回的字符串。我需要一些帮助。 这是我的代码:
[WebMethod]
public string PopulateData(string coursename)
{
return "called";
}
这是jquery方法:
var subject = 'database';
$.ajax({
type: "POST",
url: "CourseDetail.aspx/PopulateData",
data: "{coursename:'" + subject + "'}",
success: function (msg) {
// Do something interesting here.
alert('result : ' + msg);
}
答案 0 :(得分:0)
添加contentType和dataType。
var subject = 'database';
$.ajax({
type: "POST",
dataType: "text",
contentType: "application/json; charset=utf-8",
url: "CourseDetail.aspx/PopulateData",
data: "{coursename:'" + subject + "'}",
success: function (msg) {
// Do something interesting here.
alert('result : ' + msg);
}