Tuesday, 15 January 2013

javascript - Failed to load resource in ajax call -



javascript - Failed to load resource in ajax call -

consider code:

function drawcharts2() { var jsondata2 = $.ajax({ url: "http://**.**.**.**:9001/jolokia/read/*", datatype:"json", async: false }).responsetext; var parsed2 = json.parse(jsondata2);

the above url contains no value @ startup of web app. info in url come after 2-3 minutes.

when start web app. gives error, workaround have set page refresh time 30 seconds. after 30 seconds table generates successfully.

i need way that, if url not contain data, code should not give error. should skip whole code. how can accomplish this?

try

var parsed2; function drawcharts2() { $.ajax({ type: "get", url: "http://**.**.**.**:9001/jolokia/read/*", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (response) { if(response) { parsed2 = response; } else { drawcharts2(); // retry if want to.. } }, error: function (event) { alert("transmission failed. (an error has occurred)"); } }); if( parsed2 != null) { var arr2 = []; for(var x in parsed2) { arr2.push(parsed2[x]); } var array_keys = new array(); var array_values = new array(); } }

javascript jquery ajax

No comments:

Post a Comment