解析webmethod中ajax请求传递的对象列表

时间:2013-05-30 16:54:18

标签: c# javascript web-services

我正在制作一个保存数据的ajax请求,可以通过一个请求保存多个记录。

这是我的javascript函数

function savePartRequestMail() {   // send part request mail
var textPN = new Array();
var textPD = new Array();
var textPQ = new Array();
$('.txtPn').each(function () {
    var tvalue = $(this).val();
    if (tvalue != "") {

        textPN.push(tvalue);
    }
});
$('.txtPD').each(function () {
    var tvalue = $(this).val();
    if (tvalue != "") {
        textPD.push(tvalue);
    }
});
$('.txtPQ').each(function () {
    var tvalue = $(this).val();
    if (tvalue != "") {
        textPQ.push(tvalue);
    }
});
var PartRequest = {};
PartRequest.PartNumber = textPN;
PartRequest.PartDetail = textPD;
PartRequest.PartQty = textPQ;
$.ajax({
    type: 'POST',
    url: 'wom_service.asmx/sendPartRequestMail',
    // data: '{"pno" : "' + textPN + '", "pdetail" : "' + textPD + '","pQTY" : "' + textPQ + '", ,"oid" : "' + oid + '"}',
    data: JSON.stringify({ plist: PartRequest, oid: oid }),
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function (msg) {
        alert('e-mail sent successfully');
        $('#pRequestPopup').simpledialog2('close');
    },
    error: function (result) {
        alert("Could not complete request");
    }
});

}

将数据传递为

{"plist":{"PartNumber":["sdfasf","dsf","sf"],"PartDetail":["dsf","sfdsf","sf"],"PartQty":["sdf","sf","sf"]},"oid":"100003"}

WEBMETHOD

 public string sendPartRequestMail(PartRequest plist, int oid)
    {
       // here i want to get each list item 
        return "w";

    }

如何从"PartNumber":["sdfasf","dsf","sf"],开始获取每个项目的每个项目,等等,我是否正在制定错误的程序

0 个答案:

没有答案