今天发现一位大牛用的一种Ajax,感觉和前面用过的不一样,丢上来分享下
$.ajax({
type: "Post",
url: "ProjectAllList.aspx/SetImportProject",//------------不同点,提交到一个页面的静态方法中SetImportProject是ProjectAllList中的一个静态方法
data: "{'pid':'" + pid + "','mid':'" + mid + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$.ligerDialog.closeWaitting();
if (msg.d == "1") {
$.ligerDialog.warn("标注失败,请重试!");
}
if (msg.d == "2") {
document.getElementById(importID).className = "Attention_no";
document.getElementById(importID).title = "添加关注";
$.ligerDialog.warn("操作成功。");
}
if (msg.d == "3") {
document.getElementById(importID).className = "Attention";
document.getElementById(importID).title = "取消关注";
$.ligerDialog.warn("操作成功。");
}
}
});
ProjectAllList中SetImportProject方法,注意点这个方法里面不能使用服务器控件
[WebMethod]
public static string SetImportProject(int pid,int mid) { string SetStatus = "0"; //操作状态 try { } catch (Exception) { SetStatus = "1"; //标注失败 } return SetStatus; }
原文链接:/ajax/165079.html