I have a basic web app - it is bug free for a while. Occasionally - for what I expect is some network issue, I am unsure - And only on a phone (Android / chrome) - The basic AJAX returns an error - but there is no value.
This is driving me a bit crazy - as I do not know how to debug an error that is blank.
Basic AJAX post:
$.post("<?php echo base_url(); ?>"+controller_G+"/"+Method_Param_G+"?"+Math.random()+"&SEARCH_STRING="+SEARCH_STRING_G, $("#"+Data_G).serialize(), function(data, status){ }).done(function(data){ // OWNER SEARCH VIA APP if(data.indexOf("Search term found:") > -1){ // Happy Days! :) } }).fail(function(xhr, textStatus, errorThrown){ $("#ajax_message").modal(); $("#ajax_error_message_inner_text").html(textStatus+" -> "+errorThrown+" -> "+xhr.responseText); });
The ajax_message produces "error -> -> undefined"
I can not replicate this error in my desktop browser chrome - all seems fine there.
Would also be helpful to know: What are the typical ways to debug in android/iphone anyway? And what are the typical errors with AJAX on a phone?
When I reload the page on the phone - normal operation returns for a while. eventually another error returns.
2 Answers
Answers 1
Error event don`t have "xhr, status, error" params.
Try this:
$.ajax({ url: "<?php echo base_url(); ?>"+controller_G+"/"+Method_Param_G+"?"+Math.random(), type: 'POST', data: formData, cache: false, contentType: false, processData: false, success:function(data){ // Happy days :) }, error: function(jqXHR, exception){ var msg = ""; console.log(jqXHR); if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.'; } else if (jqXHR.status == 404) { msg = 'Requested page not found. [404]'; } else if (jqXHR.status == 500) { msg = 'Internal Server Error [500].'; } else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.'; } else if (exception === 'timeout') { msg = 'Time out error.'; } else if (exception === 'abort') { msg = 'Ajax request aborted.'; } else { msg = 'Uncaught Error.\n' + jqXHR.responseText; } console.log(msg); }});
Answers 2
Debug the app using chrome developer tools. Go through this Link
After setup the Ajax Error can then be seen in Network tab just like any other normal web debugging.
0 comments:
Post a Comment