前端JS:
function getAjaxData() {
var strResult = "";
$.ajax({
type: 'post',
url: encodeURI(‘Manage.aspx/GetConfigUrl’),
data: "{}",
contentType: "application/json;charset=utf-8",
dataType: "json",
cache: false,
async: false,
success: function () {
return data;
},
error: function (err) {
if (err.responseText !== null && err.responseText !== '') {
alert(err.responseText);
}
}
});
return strResult;
}
后台:普通asp.NET项目代码类,AJAX访问的函数接口,需要增加 [WebMethod],并且函数接口为static静态函数。
using System.Web.Services;
public partial class Manage : Page