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 () {
            }
        });

 

posted on 2011-04-15 18:22  一粒沙  阅读(359)  评论(0编辑  收藏  举报