2017-05-26 28 views
0

好吧,這聽起來超級簡單,但我仍然沒有找到可以幫助我的答案。得到ajax返回值在jQuery的功能

我有一個jQuery函數

$.ajax({ 
    url: '<?php echo base_url(); ?>index.php/Im_general/obtenerDireccionAlmacen', 
    method: 'POST', 
    data: { 
     idAlmacen: idAlmacen 
    }, 
    success: function (returned) { 
     var result = JSON.parse(returned); 
     console.log(result.direccion); 
     //here I set the returned string as input value 
    } 
}); 

我把從數據庫的功能,並期望一個字符串,我會追加到一個文本里面輸入這個Ajax回調。 在控制檯輸出中,我可以驗證回調是否正常工作,如圖所示。但我仍然不知道如何獲得強調的價值。

Console output

此外,我應該用更迭或回調呢?

+0

嘗試:執行console.log((result.direccion)[0] .domicile); – tech2017

+0

@techLove謝謝!有用。 – raptorandy

回答

2

這只是一個對象。

console.log((result.direccion)[0].domicile); 
1

result.direccion [0] .domicile會滿足您的需求