javascript - jQuery .getJSON() URL Error -
this json data retrieved when use (method redacted)
method:
[{ "group_option": { "optionsid": "28", "menugroupid": "6", "group_options_name": "select 2 (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 } }] } }]
here other relevant code:
<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(); (var = 0; < 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>'; (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>
i've used .ajax
, i've gotten nothing , i'm trying use .getjson
. still haven't been able retrieve data website. seems never want past .getjson(url, function(data)
my questions
1.why won't code let me .getjson
function?
2.what need change access data in .getjson
function?
add fail function getjson method , see if errors there
$.getjson("", function(){ .... }) .fail(function( jqxhr, textstatus, error ) { var err = textstatus + ", " + error; console.log( "request failed: " + err ); })
Comments
Post a Comment