将json_encode()数组插入javascript函数

时间:2016-03-07 15:11:03

标签: javascript php jquery arrays

您好我从php使用ajax获取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的初学者

1 个答案:

答案 0 :(得分:0)

将php json_encode数组存储在变量

var data=xmlhttp.responseText;

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

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

你完成了!