简体   繁体   English

如何通过Jquery将数组字符串[]传递给Web服务?

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

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

Javascript; 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#: 在C#中:

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

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. 假设ids是一个JavaScript字符串数组,那就是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM