javascript - 当 xmlhttp.status != 200 时如何抑制 JavaScript 错误

标签 javascript xmlhttprequest

在我的 Google Chrome 控制台中,当 xmlhttp 状态未导致 200 时,我不断收到错误。例如,在某些情况下,我故意将 PHP 文件的 header 设置为 500,以便在 javascript 中我可以显示错误并避免任何情况这需要 PHP 文件。由于我有自己的错误处理程序,是否有办法抑制默认错误?

错误示例:

POST http://localhost/mama/cgi-bin/pages/Module-Install.php 500 (Internal server error) 

最佳答案

在自己处理错误时,似乎无法抑制 google chrome 中的这些警告。对于任何正在寻找替代解决方案的人,请将错误代码嵌入到 json 对象中,并在客户端解析 json 对象以查找任何错误。

关于javascript - 当 xmlhttp.status != 200 时如何抑制 JavaScript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423734/

相关文章:

javascript - 除了使用 eval/handleAs : "javascript" to dynamically fetch scripts (via XMLHttpRequest) 之外,还有什么办法吗

javascript - 我如何将 a 标签链接到 onload 模态窗口?

javascript - 使用包含列表的 json 数据发送 post 请求

javascript - 在 jQuery .get() 的 Data 对象中查找元素

javascript - 如何防止 angular.js $http 对象发送 X-Requested-With header ?

javascript - 我如何使用 javascript 调用 Sharepoint Web 服务?

asp.net-core - 有没有办法阻止 Postman 在 .NET Core 中发出的 HTTP 请求?

javascript - 多次追加加载的 HTML

javascript - CSS 替代 CSS 加号选择器?

javascript - Sails.js 使用路由过滤记录