2013-04-22 58 views
0

我有一個問題與jQuery getJSON和取代結果。jquery getJson和數組

jQuery代碼

jQuery(document).ready(function(){ 
jQuery.getJSON("gsm.php",{getproducts:'495074, 495061, 495060'},function(response){ 
    jQuery.each(response, function() { 
     jQuery('#item1').html(response.item1); 
     jQuery('#item2').html(response.item2); 
    }); 

}); 
}); 

gsm.php JSON響應

[ 
{ 
    "item1": "test data 1", 
    "item2": "test data 1a" 
}, 
{ 
    "item1": "test data 2", 
    "item2": "test data a" 
} 
] 

我很抱歉,但我不能與其他職位解決我的問題。

我將不勝感激任何幫助。

謝謝!

+2

啊......你的問題是什麼? – 2013-04-22 10:31:55

回答

1
$(document).ready(function() { 

     $.getJSON("gsm.php", { getproducts: '495074, 495061, 495060' }, function(response) { 
      $.each(response, function(key, value) { 
       $('#item1').html(value.item1); 
       $('#item2').html(value.item2); 
      }); 
     }); 

    }); 

你已經錯過了這個function(key, value)和使用價值從JSON獲取數據。

+0

謝謝,這就像一個魅力:) – 2013-04-22 11:32:39

0

試試這個 -

jQuery.each(response, function(index,value) { 
     jQuery('#item1').html(value.item1); 
     jQuery('#item2').html(value.item2); 
}); 
0

試試這個

jQuery.each(response, function() { 
    jQuery('#item1').html(this.item1); 
    jQuery('#item2').html(this.item2); 
});