简体   繁体   中英

Insert json_encode() array into javascript function

Hi i am getting json_encode() array from php using ajax and storing that into a variable. how can i insert that array into javascript function?.

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

it should look like this.

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"
                    }
                }),

Please help, i am a beginner in javascript

Store the php json_encode array in a variable

var data=xmlhttp.responseText;

then just use JSON.parse to parse the array

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

you are done!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM