您好,請我無法從中通過ajax返回以下陣列獲取數據:獲取從JSON數組數據
Array
(
[routes] => Array
(
[0] => Array
(
[route_id] => 4
[company_id] => 2
[from] => Soye
[to] => Martelange
[fare] => 98
[is_active] =>
)
[1] => Array
(
[route_id] => 9
[company_id] => 2
[from] => Auckland
[to] => Stevoort
[fare] => 65
[is_active] =>
)
[2] => Array
(
[route_id] => 11
[company_id] => 2
[from] => Bowden
[to] => Kessel
[fare] => 60
[is_active] =>
)
[3] => Array
(
[route_id] => 17
[company_id] => 2
[from] => Berg
[to] => Clearwater Municipal District
[fare] => 97
[is_active] =>
)
[4] => Array
(
[route_id] => 24
[company_id] => 2
[from] => Martelange
[to] => Soye
[fare] => 98
[is_active] =>
)
[5] => Array
(
[route_id] => 29
[company_id] => 2
[from] => Stevoort
[to] => Auckland
[fare] => 65
[is_active] =>
)
[6] => Array
(
[route_id] => 31
[company_id] => 2
[from] => Kessel
[to] => Bowden
[fare] => 60
[is_active] =>
)
[7] => Array
(
[route_id] => 37
[company_id] => 2
[from] => Clearwater Municipal District
[to] => Berg
[fare] => 97
[is_active] =>
)
)
)
這是我的javascript:
var data = {id:id}; //Array
$.ajax({
url : url+"ticketinfo/routes",
type: "POST",
data : data,
success: function(data, textStatus, jqXHR)
{
var jsonArray = data.routes;
var options = $("#options");
$.each(jsonArray , function(index, data) {
//adds all this values fron the array ,only from and to
options.append($("<option/>").text(data.from + "/" + data.from));
});
},
error: function (jqXHR, textStatus, errorThrown)
{
}
});
而且通過麻煩我的意思是我不知道如何,我在這裏嘗試了幾個例子,但沒有爲我工作。我想要做的就是在數組中獲取這兩個字段:從和到使用該數據動態地使用jquery動態填充兩個選擇控件。如果有人能幫我解決這個問題,我將非常感激。先謝謝你。 :)
類型錯誤:路由未定義 for(var i = 0; i
2014-09-22 21:45:31