gpt4 book ai didi

ajax - 从 AJAX 获取错误消息时出现问题 - 仅在电话上出错

转载 作者:行者123 更新时间:2023-12-02 01:00:09 25 4
gpt4 key购买 nike

我有一个基本的网络应用程序 - 它有一段时间没有错误。偶尔 - 对于我所期望的一些网络问题,我不确定 -并且仅在手机(Android/chrome)上 - 基本 AJAX 返回错误 - 但没有任何值(value)。

这让我有点抓狂——因为我不知道如何调试一个空白的错误。

基本的 AJAX 帖子:

$.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);
});

ajax_message 产生“error -> -> undefined

我无法在我的桌面浏览器 chrome 中复制此错误 - 一切似乎都很好。

了解以下内容也会有所帮助:无论如何,在 android/iphone 中调试的典型方法是什么?手机上 AJAX 的典型错误是什么?

当我在手机上重新加载页面时 - 会暂时恢复正常操作。最终返回另一个错误。

最佳答案

错误事件没有“xhr、状态、错误”参数。

试试这个:

$.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);
}});

关于ajax - 从 AJAX 获取错误消息时出现问题 - 仅在电话上出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51201732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com