jquery调用asp.net的WebService
asmx.cs
using System.Web.Script.Services;
[System.Web.Script.Services.ScriptService]
public class test : System.Web.Services.WebService
{
[ScriptMethod(UseHttpGet = true)]
public void testMethod(int id)
{
}
}
js
$.ajax({
url: 'test.asmx/testMethod',
dataType: "json",
data: "id=2",
beforeSend: function(x) {
x.setRequestHeader("Content-Type", "application/json; charset=utf-8");
},
success: function(json) {
var o = eval("(" + json.d + ")");
callBack(o);
}
});
或者向下面这样直接使用也行,原因暂时不明
$.ajax({
type: "POST",
url: "/test.asmx/testMethod",
data: {
htmlStr: "<font color='red'>你好</font>",
Co: 877,
Tablename: "table_2",
buttonId: 96
},
success: function () {
alert("success");
},
error: function () {
}
});
type: "POST",
url: "/test.asmx/testMethod",
data: {
htmlStr: "<font color='red'>你好</font>",
Co: 877,
Tablename: "table_2",
buttonId: 96
},
success: function () {
alert("success");
},
error: function () {
}
});
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步