我正在使用jquery post發送一些值給服務器端。作爲迴應,我收回字符串。然後,我正在使用它並通過使用JSON.parse()轉換成一個對象...當我在查看控制檯日誌時,我看到了對象,這對我來說看起來很好。現在當我試圖循環對象並試圖檢索值時,我無法遍歷它。我不知道我在這裏錯過了什麼。我上的變化上發送的值event..so基本for循環的變化事件無法循環訪問對象
這裏運行每次都是我的js
$(function(){
var categoryChoiceVal = '';
var x = [];
var html = '';
$('select').change(function() {
categoryChoiceVal = $('.categoryChoice option:selected').text().replace(/ /g, '%20');
$.post("ajax.php", { categoryChoiceVal:categoryChoiceVal},function(data) {
x = $.parseJSON(data)
console.log(x);
});
$.each(x, function(){
html += this.address;
});
$('.dataContainer').html(html);
});
});
這裏是我做的這個頁面。 http://soumghosh.com/otherProjects/phpDataOperation/eventcCalendar/testOne.php
同一問題每天要問十次。可能重複的[如何從AJAX調用返回響應?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – meagar