2016-03-07 51 views
0

您好,我使用ajax從php獲取json_encode()數組並將其存儲到變量中。我怎樣才能將該數組插入到JavaScript函數?將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

+3

'var foo = <?php echo json_encode($ somearray); ?>; var myarr = [「data」:foo];' –

+1

昨天你問了同樣的問題,忽略了顯示更多代碼上下文的請求。 ajax代碼在哪裏?所示的結構也沒有意義 – charlietfl

回答

0

Store中的PHP json_encode數組變量

var data=xmlhttp.responseText; 

那麼就使用JSON.parse解析陣列

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

你完成了!