Problems getting error message from AJAX - error on phone only

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Problems getting error message from AJAX - error on phone only



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.



The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.



There must be a method by which - the ajax return errors must be clearly identifying the error or problem back to the user





Sorry - I messed up the first time - the question has been adjusted
– Stnfordly
yesterday




1 Answer
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);
}});





Sorry - I messed up and added the wrong code the first time - it is still similar - can not get an error message that is meaningful
– Stnfordly
yesterday






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS