我遇到了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"
}
]
对不起,我无法解决其他帖子的问题。
我将不胜感激。
谢谢!
答案 0 :(得分: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获取数据。
答案 1 :(得分:0)
试试这个 -
jQuery.each(response, function(index,value) {
jQuery('#item1').html(value.item1);
jQuery('#item2').html(value.item2);
});
答案 2 :(得分:0)
试试这个
jQuery.each(response, function() {
jQuery('#item1').html(this.item1);
jQuery('#item2').html(this.item2);
});