jQuery处理/隐藏预期的Ajax 404错误 [英] jQuery handle/hide expected Ajax 404 Error
问题描述
我使用ajax头请求来检查文件. 在大多数情况下,该文件将不存在,并且最好以某种方式阻止404在我的调试控制台中显示.有没有一种好的方法可以实现这一目标?
I use an ajax head request to check for a file. In most cases the file wouldn't exist and it would be nice to somehow prevent the 404 to show up in my debug console. Is there a nice way to achieve that?
请明确说明: http://jsfiddle.net/kannix/FFLdP/
推荐答案
不,不幸的是,您不能.
No, unfortunately, you cannot.
404错误是在内部处理的,即使覆盖JavaScript中的错误事件或尝试捕获该错误事件,也无法抑制该错误.
404 errors are handled internally, you cannot suppress the error, not even with overwriting the error events in javascript or try-catching it.
您可以编写服务器脚本来检查某个文件是否存在,然后在调用可能不存在的文件之前调用该文件以检查文件是否存在.
You could write a serverscript to check if a certain file exists and call that one to check if the file exists before calling the file that might not exist.
这篇关于jQuery处理/隐藏预期的Ajax 404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!