Clash 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
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);
}});
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.
Sorry - I messed up the first time - the question has been adjusted
– Stnfordly
yesterday