0
這是檢索的JSON數據當我使用(METHOD REDACTED)
方法:jQuery的.getJSON()URL錯誤
[{
"group_option": {
"OptionsID": "28",
"MenuGroupID": "6",
"group_options_name": "Select two (2) sides :",
"menu_group_option_information": null,
"menu_group_option_min_selected": "0",
"menu_group_option_max_selected": "2",
"fDateAdded": "2014-01-25 08:29:20",
"group_option_items": [{
"item": {
"OptionItemID": "69",
"menu_item_option_name": "Mexican rice",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "70",
"menu_item_option_name": "Refried beans",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "71",
"menu_item_option_name": "Poblano rice",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "72",
"menu_item_option_name": "Charro beans",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "73",
"menu_item_option_name": "Caesar salad",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "74",
"menu_item_option_name": "Southwestern mashed potatoes",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "75",
"menu_item_option_name": "Roasted corn succotash",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "76",
"menu_item_option_name": "Poblano cheese corn grits",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "77",
"menu_item_option_name": "French Fries",
"menu_item_option_additional_cost": null
}
}, {
"item": {
"OptionItemID": "78",
"menu_item_option_name": "Fiesta salad",
"menu_item_option_additional_cost": null
}
}]
}
}]
這裏是我的其他相關代碼:
<html>
<head>
<meta charset="utf-8" />
<script src="../JQUERY/jquery-1.11.0.js"></script>
<script>
function getOptions() {
var html = new String();
$.getJSON('<URL HERE>', function (data) {
alert("function");
//var data = JSON.parse(data);
var h = new String();
for (var i = 0; i < data.length; i++) {
h += '<div class="data">';
h += data[i]['group_option'].OptionsID + '<br>';
h += data[i]['group_option'].MenuGroupID + '<br>';
h += data[i]['group_option'].group_options_name + '<br>';
h += data[i]['group_option'].menu_group_option_information + '<br>';
h += data[i]['group_option'].menu_group_option_min_selected + '<br>';
h += data[i]['group_option'].menu_group_option_max_selected + '<br>';
h += data[i]['group_option'].fDateAdded + '<br><br><br>';
for (var iter = 0; iter < data[i]['group_option']['group_option_items'].length; iter++) {
h += data[i]['group_option']['group_option_items'][iter]['item'].OptionItemID + '<br>';
h += data[i]['group_option']['group_option_items'][iter]['item'].menu_item_option_name + '<br>';
h += data[i]['group_option']['group_option_items'][iter]['item'].menu_item_option_additional_cost + '<br>';
h += '<br><br><br>';
}
h += '</div>';
}
alert("h");
alert(h);
html = h;
alert("html equals ");
alert(html);
});
alert("returning html");
alert(html);
return html;
}
</script>
<script>
$(document).ready(function() {
var str = "";
str = getOptions();
$('#content').append(str);
});
</script>
</head>
<body>
<div id="content"></div>
</body>
我用.ajax
,我什麼都沒有,現在我試圖使用.getJSON
。我仍然無法從網站檢索數據。它似乎從來沒有想過去.getJSON(url, function(data)
我的問題
1.爲什麼不會我的代碼讓我進入我的.getJSON
功能?
2.在我的.getJSON
函數中,需要更改哪些數據才能訪問我的數據?
您在控制檯的錯誤,你可能需要使用的console.log()而不是警報()以及 – kennypu
IM沒有得到任何錯誤 – Jonathan
檢查jQuery庫的路徑是否正確 – SajithNair