0

我想将一个数组传递给 ac# webmethod,但没有一个很好的例子可以效仿。感谢您的任何帮助。

这是我到目前为止所拥有的:

我的数组:

function ReadAllGridviewData() {

    var ArrayUph = new Array();

    GVUPHLineItems = document.getElementById("GVUPHLineItems");
    for (var i = 1; i < GVUPHLineItems.rows.length; i++) {
        var txtQty = GVUPHLineItems.rows[i].cells[1].getElementsByTagName('input');
        var txtStyle = GVUPHLineItems.rows[i].cells[2].getElementsByTagName('input');
        var spanstyleDesc = GVUPHLineItems.rows[i].cells[3].getElementsByTagName('span');
        var txtPackage = GVUPHLineItems.rows[i].cells[4].getElementsByTagName('input');
        var txtPrice = GVUPHLineItems.rows[i].cells[7].getElementsByTagName('input');
        if (txtStyle[0].value != '' && txtQty[0].value !='') {
            var ArryUph = new Array();
            ArryUph['LineNumber'] = i;
            ArryUph['Quantity'] = txtQty[0].value;
            ArryUph['Style'] = txtStyle[0].value;
            ArryUph['StyleDescription'] = spanstyleDesc[0].innerHTML;
            ArryUph['Package'] = txtPackage[0].value;
            ArryUph['SelectFlag'] = 'N';
            ArryUph['Price'] = 0.0;
            var ArryStyle = new Array();
            for (var j = 0; j < 6; j++) {
                var spanStyle = GVUPHLineItems.rows[i].cells[5].childNodes[1].childNodes[1].childNodes[1].childNodes[j].cells[0].innerText;
                var inputCoverId = GVUPHLineItems.rows[i].cells[5].childNodes[1].childNodes[1].childNodes[1].childNodes[j].cells[1].getElementsByTagName('input');
                var inputColorID = GVUPHLineItems.rows[i].cells[5].childNodes[1].childNodes[1].childNodes[1].childNodes[j].cells[2].getElementsByTagName('input');
                if (inputCoverId[0].value != '' && inputColorID[0].value != '') {
                    var tempArryStyle = new Array();
                    tempArryStyle['CoverPosition'] = spanStyle;
                    tempArryStyle['CoverID'] = inputCoverId[0].value;
                    tempArryStyle['ColorID'] = inputColorID[0].value;
                    ArryStyle.push(tempArryStyle);
                }
            }
            var ArryOptions = new Array();
            for (var k = 0; k < 6; k++) {
                var inputOpt = GVUPHLineItems.rows[i].cells[6].childNodes[1].childNodes[1].childNodes[1].childNodes[k].cells[0].getElementsByTagName('input');
                if (inputOpt[0].value != '') {
                    var tempArryOptions = new Array();
                    tempArryOptions['Opt'] = inputOpt[0].value;
                    ArryOptions.push(tempArryOptions);
                }
            }
            ArryUph['StyleCovers'] = ArryStyle;
            ArryUph['Options'] = ArryOptions;
            ArrayUph.push(ArryUph);
        }
    }

这是我的 Jquery 调用:

$.ajax({ type: "POST",
         url: "OrderEntry.aspx/ValidateUph",
         data: JSON.stringify({ ArrayUph: ArrayUph }),
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (data) {
              var validstyle = data.d;
         }
 });
4

0 回答 0