$.getJSON("suppliermanagement.ashx", { action: "gsupplierinvoice", SupllierID: Supplierid }, function (data) {
alert("purchaseinvoice called");
alert(JSON.stringify(data))
var JsonInvoice = JSON.stringify(data);
$.each(data, function (key, item) {
// var invdata = data[i];
$("#Gridinvoice").append('<tr><td class="auto-style36" style="border-style: solid; border-width: thin">' + item.InvoiceDate + '</td><td class="auto-style36" style="border-style: solid; border-width: thin">' + item.SuppliersInvoiceNumber + '</td><td class="auto-style36" style="border-style: solid; border-width: thin"></td><td class="auto-style36" style="border-style: solid; border-width: thin">' + item.Type + '<td></tr>')
});
});
上面是我以json格式获取数据的函数,但我无法使用for循环和foreach循环进行追加。显示未定义。如何使用for循环在表中添加数据?
这是结果 JSON.stringify(data)
{“ Dpurchaseinvoice”:[{“ pInvoiceDate”:“ / Date(1405708200000)/”,“ pSupplierInvoiceNumber”:“ G003”,“ pType”:1},{“ pInvoiceDate”:“ / Date(1405708200000)/”,“ pSupplierInvoiceNumber“:” H008“,” pType“:1}],” ErrorMessage“:”“,” mID“:0,” mJobID“:null,” mSupplierID“:null,” mInvoiceDate“:” / Date(-62135596800000 )/“,” mOurRef“:0,” mSupplierInvoiceNumber“:null,” mPurchaseOrderRef“:null,” mType“:0,” mPaid“:null,” mReferencePurchaseInvoiceID“:null,” supplier“:null,” JobID“: null,“ ID”:0,“ SupplierID”:null,“ InvoiceDate”:“ / Date(-62135596800000)/”,“ OurRef”:0,“SuppliersInvoiceNumber“:空,” PurchaseOrderRef“:空,”类型“:0,”已付费“:空,” ReferencePurchaseInvoiceID“:空,” ErrorSummary“:空,” ErrorList“:[]}
您的代码有效。也许选择器#Gridinvoice
是错误的。
编辑:这是您的代码,已更新为使用JSON数据:
$.each(data.Dpurchaseinvoice, function (key, item) {
$("#Gridinvoice").append('<tr><td class="auto-style36" style="border-style: solid; border-width: thin">' + item.pInvoiceDate + '</td><td class="auto-style36" style="border-style: solid; border-width: thin">' + item.pSupplierInvoiceNumber + '</td><td class="auto-style36" style="border-style: solid; border-width: thin"></td><td class="auto-style36" style="border-style: solid; border-width: thin">' + item.pType + '<td></tr>')
});
注意data.Dpurchaseinvoice
和前缀item.pXXX
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句