我在ASP.NET中进行JQueryAjax调用,我用WebMethod返回字符串,但是在Ajax调用成功后,我得到了页面的完整HTML,我还使用了类型:“get”但没有用。下面是我的Ajax调用代码:
$.ajax({
type: "POST",
url: "MyPage.aspx/GetData", //url to point your webmethod
success: function (Result) {
if (Result != "")
alert( Result);
},
error: function () { alert('error'); }
});
[System.Web.Services.WebMethod()]
public string GetData()
{
//getting value from Database and returning
}
我在MyPage.aspx中调用Ajax。