Sunday, 15 June 2014

javascript - Ajax Request Does not Respond -



javascript - Ajax Request Does not Respond -

i have next script;

function fetchnews(user_id,api_token){ $.ajax({ type:'get', url: 'http://192.168.**.**/mysite/public/index.php/api/v1/news/'+user_id, headers: {'x-auth-token' : api_token}, datatype:'json', success: function(data) { var comment=''; for(var = 0; < data.length; i++) { comment = data[i]; $('headlines').append('<li><a href="news_details.html" rel="external"><h2>'+ comment.news_headline +'</h2><p><strong>'+ comment.news_content +'</strong></p><p class="ui-li-aside"><strong>'+ comment.created_at +'</strong></p></a></li>'); } }, error: function(jqxhr, exception) { if (jqxhr.status === 0) { alert("not connected. verify network.");//show error } else if (jqxhr.status == 404) { alert("requested page not found. [404]");//show error } else if (jqxhr.status == 500) { alert("internal server error [500].");//show error } else if (exception === 'parsererror') { alert("requested json parse failed.");//show error } else if (exception === 'timeout') { alert("time out error.");//show error } else if (exception === 'abort') { alert( "ajax request aborted.");//show error } else { alert("uncaught error.\n" + jqxhr.responsetext);//show error } } }); }

i phone call fetchnews function page loads, @ bottom of page close </body> tag. function called no responds server @ all, , when checked logcat, requeststate(status) stuck @ 1

change this...

datatype:'json',

to this...

datatype:'jsonp',

datatype: jsonp cross-domain requests/different domain origin. datatype:json same domain-same origin request.

but also...this seems wrong..

$('headlines').append('<li><a href="news_details.html" rel="external"><h2>'+ comment.news_headline +'</h2><p><strong>'+ comment.news_content +'</strong></p><p class="ui-li-aside"><strong>'+ comment.created_at +'</strong></p></a></li>');

should maybe be

$('.headlines') or $('#headlines')

javascript jquery ajax

No comments:

Post a Comment