js+json+webservice(List<>作为参数)
client端:
function Save(){
var data_temp = convert_To_Json(checkbox_selected());
//alert(data_temp);
$.ajax({
type: "post",
contentType: "application/json",
url: WebServiceUrl + "/CreateOrder_CreateSO",
data: ‘{"list":‘ + data_temp + ‘,"Id":"0"}‘,
dataType: "json",
success: function (d) {
if (d.d == null || d.d == undefined) {
alert("Please Login");
window.location.href = "Login.html";
return;
}
alert(d.d);
},
error: function (e) { alert("Error"); }
});
}
function convert_To_Json(ar_data) {
var temp = "";
for (var i = 0; i < ar_data.length; i++) {
var ar_temp = ar_data[i];
temp += ‘{"Product":"‘ + ar_temp[0] + ‘","Set":"‘ + ar_temp[1] + ‘","Qty":"‘ + ar_temp[2] + ‘","Price":"‘ + ar_temp[3] + ‘"},‘;
}
temp = temp.substr(0, temp.length - 1);
temp = ‘[‘ + temp + ‘]‘;
return temp;
}
function checkbox_selected() {
var ar = document.getElementsByName("ckb_Product");
var ar_checked = new Array();
for (var i = 0; i < ar.length; i++) {
if (ar[i].checked) {
var temp = ar[i].parentNode.parentNode;//.children[3].children[0];
var prodct = $(temp.children[1]).html();
var set = $(temp.children[2]).html();
var Qty = $(temp.children[3].children[0]).val();
var Price = $(temp.children[4].children[0]).val();
var ar1 = new Array();
ar1.push(prodct);
ar1.push(set);
ar1.push(Qty);
ar1.push(Price);
ar_checked.push(ar1);
}
}
return ar_checked;
}
webservice端:
[WebMethod(EnableSession = true)]
public string CreateOrder_CreateSO(List<Set_Product_List> list, string Id)
{
string re_value = Id;
return re_value;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。