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

2019-02-18 15:00发布

问题:

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.



标签: c# jquery asmx