将 json_encode() 数组插入 javascript 函数


Insert json_encode() array into javascript function

嗨,我正在使用 ajax 从 php 获取 json_encode() 数组并将其存储到变量中。 如何将该数组插入JavaScript函数?

c = (parseInt(e.attr("data-invoice-id")), {                                     
//insert that array here
                }),

它应该看起来像这样。

c = (parseInt(e.attr("data-invoice-id")), {                                     
                    invoice_id: {
                        invoice_number: "Some Value",
                        invoice_orderno: "Some Value",
                        invoice_date: "Some Value",
                        invoice_due_date: "Some Value",
                        invoice_from_company: "",
                        invoice_from_address_1: "",
                        invoice_from_address_2: "India",
                        invoice_to_company: "Some Value",
                        invoice_to_address_1: "2894 Bond Street",
                        invoice_to_address_2: "Providence, RI 02908",
                        invoice_total_value: "Some Value",
                        invoice_vat_value: "00.00",
                        invoice_device: "Some Value",
                        invoice_dproblem: "Some Value",
                        invoice_dserial: "Some Value",                            
                        invoice_payment_info: "Cash On Delivery<br/>(COD)",
                        invoice_payment_due: "14"
                    }
                }),

请帮忙,我是javascript的初学者

将 php json_encode数组存储在变量中

var data=xmlhttp.responseText;

然后只需使用 JSON.parse 来解析数组

    c = (parseInt(e.attr("data-invoice-id")), {                                     
          var obj = JSON.parse(data)  
           }),

大功告成!