检查是否为 401、404、500、其他 jquery/javascript
也许我的想法是错误的。但无论如何。目前,在 jQuery 的帮助下,我正在运行 $.post()。
不过,我发帖是为了获取基于目录的内容。问题是信息是动态设置的。因此,如果事实证明我在某种意义上查询文件/文件夹并且它不存在,我会收到 404、401、500 等错误。简而言之,就是告诉我它不存在。也就是说,我如何检查或捕获它,以便当它发生时我可以通过 javascript 通过对话框或其他东西抛出自定义错误。
有可能吗?请注意,ajax/post 目前并未绑定到服务器端脚本,如果最终绑定到服务器端脚本,它将绑定到 ruby on Rails 脚本。
Possible Duplicate:
jQuery $.get or $.post to catch page load error (eg. 404)
Maybe I am thinking this through wrong. But here goes anyway. Currently with the help of jQuery I am running $.post().
However I am posting to get contents based on a directory. Issue is the information is dynamically set. So if it turns out to be where I in a sense query for a file/folder and it doesn't exist I get a 404, 401, 500 whatever error.. Basicly in short telling me it doesn't exist. That said, how do I check for that, or catch it so when it occurs I can throw a custom error out via javascript through maybe a dialog or something.
Is it even possible? Mind you the ajax/post is not tied to a server side script currently and if it is to eventually be, it will be tied to a ruby on rails script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 post 调用之后添加
.error(function(){...})
以确定 AJAX 失败时的处理方式以及返回的错误代码。代码:
说明:
You can add
.error(function(){...})
right after your post call to determine how to handle if your AJAX fails, and also the error code that's returned.Code:
Explanation: