返回什么错误,如果方法仅期望Ajax调用? [英] What error to return if method expects only ajax calls?

查看:85
本文介绍了返回什么错误,如果方法仅期望Ajax调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么HTTP状态,如果它希望仅通过AJAX的使用应该采取行动的回报,但被称为没有适当的阿贾克斯头?我觉得我应该意味着一些错误,但我真的不能找到一个合适的。

What HTTP status should action return if it expects to only be used via AJAX, but was called without proper ajax headers? I feel I should signify some error, but I can't really find appropriate one.

我想最好是405不允许的方法,但它是奇怪,如果例如AJAX GET请求返回的内容,和普通GET将返回405

I guess best would be 405 Method not allowed, but it would be weird if for example ajax GET requests returned content, and plain GET would return 405.

推荐答案

可以完成请求,但你拒绝这样做,因为它不是在AJAX,所以我觉得适当的错误是403 - 禁止

You can fulfill the request, but you refuse to do it since it's not in AJAX, so I think the appropriate error is 403 - forbidden.

http://www.w3.org/Protocols/ RFC2616 / RFC2616-sec10.html#sec10.4.4

反正,我不认为任何错误code将是奇怪的,如果它会伴随着一个明确的解释。

Anyways, I don't think any error code will be weird if it'll be accompanied with a clear explanation.

这篇关于返回什么错误,如果方法仅期望Ajax调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆