现在的位置: 首页 > 综合 > 正文

JQuery ajax 传递数组

2012年03月16日 ⁄ 综合 ⁄ 共 1191字 ⁄ 字号 评论关闭

页面调用部分:

$('#btn').click(function () {
    $.ajax({
        type: 'post',
        url: './GridTable.aspx/call',
        contentType: "application/json; charset=utf-8",
        data: '{"userinfo":[{"name":"zs","age":"21"},{"name":"ls","age":"25"}]}',
        dataType: 'json',
        success: function (result) {
            alert(result.d);
        }
    });

    return false;
});

后台调用部分,两种方法均可
[WebMethod]
public static string call(Dictionary<string,string>[] userinfo)
{
    System.Threading.Thread.Sleep(5000);
    return str[0]["name"];
}

[WebMethod]
public static string test(List<UserinfoEntity> userinfos) {
    System.Threading.Thread.Sleep(5000);
    foreach (UserinfoEntity userinfo in userinfos) {
        return order.rowid;
    }

    return "什么也没有";
}

 

页面调用部分:

$('#btn').click(function () {
    $.ajax({
        type: 'post',
        url: './GridTable.aspx/call',
        contentType: "application/json; charset=utf-8",
        data: '{"userinfo":[{"name":"zs","age":"21"},{"name":"ls","age":"25"}]}',
        dataType: 'json',
        success: function (result) {
            alert(result.d);
        }
    });

    return false;
});

后台调用部分,两种方法均可
[WebMethod]
public static string call(Dictionary<string,string>[] userinfo)
{
    System.Threading.Thread.Sleep(5000);
    return str[0]["name"];
}

[WebMethod]
public static string test(List<UserinfoEntity> userinfos) {
    System.Threading.Thread.Sleep(5000);
    foreach (UserinfoEntity userinfo in userinfos) {
        return order.rowid;
    }

    return "什么也没有";
}

抱歉!评论已关闭.