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 () {
            }
        });
原文地址:https://www.cnblogs.com/timy/p/2017454.html