how do you pass an array string[] to a Web Service via Jquery?

我是研究僧i 提交于 2019-12-19 10:03:26

问题


here's my code:

var ids = $.map($("#container-1").children(), function(n, i) {
     return n.id;
});

$.ajax({
    type: 'POST',
    url: 'Loader.asmx/Active',
    data: "{'divs':'" + ids + "'}",
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {}
});

回答1:


Javascript;

var ids = $.map($("#container-1").children(), function(n, i) {
     return n.id;
});

$.ajax({
    type: 'POST',
    url: 'Loader.asmx/Active',
    data: { divs: ids.join("|") },
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {}
});

in C#:

string[] arrIds = divs.Split('|');



回答2:


I wouldn't think you'd need to render your data as a string.

Wouldn't this work?

data: { divs: ids },

Assuming that ids is a JavaScript string array, that is.



来源:https://stackoverflow.com/questions/1457637/how-do-you-pass-an-array-string-to-a-web-service-via-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!