如何發送與JS後返回到ASP.NET Web方法字符串數組,代碼樣品低於:如何通過JS發佈數組字符串返回Web方法?
function service() {
var items = $('#jqxTree').jqxTree('getCheckedItems');
// var jsonText = JSON.stringify({ list: items });
myData = {};
for (index in items) {
myData[index] = items[index].label;
}
$.ajax({
type: "POST",
url: "ServiceConfiguration.aspx/ProcessIndexes",
data: "{'jsonValue': " + JSON.stringify(myData) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
cache: false,
success: function (msg) {
}
});
//alert(items);
}
現在我有以下努力:
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static void ProcessIndexes(List<string> jsonValue)
{
var serializer = new JavaScriptSerializer();
}
你需要顯示一些代碼 –
@Andrew我已經更新了代碼示例...謝謝! – mknayab
「jsonValue」周圍有單引號...... JSON需要雙引號。 – jmar777