XMLHttpRequest在移动设备上的chrome上不起作用

XMLHttpRequest is not working on chrome on mobile device

本文关键字:不起作用 chrome 移动 XMLHttpRequest      更新时间:2023-09-26

我在前端处理核心javascript,在后端处理php,为了从后端发送和接收数据,我使用XMLHttpRequest。我的帖子请求代码是:

var request = new XMLHttpRequest();
request.open('POST', BASE_URL+'index.php/dashboard/saveEndPoint');
request.setRequestHeader('Content-Type', 'application/json');
var messageObj = {
  endPoint: endPoint,
  ipAddress:userip,
  url:window.location.href,
  browser:"Chrome"
}
request.send(JSON.stringify(messageObj));

这段代码在桌面设备上的chrome和firefox中运行良好。但当我在安卓操作系统的移动设备上使用chrome时,它不起作用。未发送请求
我通过将移动设备与桌面chrome连接来调试代码(crome://inspect)但它没有显示任何请求

帮助我找到它的解决方案。提前谢谢。

我发现了代码无法工作的问题。这是由于if-else条件,我把这个代码放在其中,由于无法用我的if条件识别移动设备上的chrome,它没有运行ajax代码

因此,感谢您的子孙和所有帮助我找到解决方案的人。