2013-04-22 2 views
0

У меня проблема с jQuery getJSON и вытеснением результата.jquery getJson и array

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

ahh ... в чем проблема? –

ответ

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

Спасибо, это работает как шарм :) –

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); 
});