【问题标题】:No response for ajax PUT, but response on ajax GET and POSTajax PUT 没有响应,但 ajax GET 和 POST 有响应
【发布时间】:2013-10-23 06:42:03
【问题描述】:

制作同域 (http://example.host.com -> http://example.host.com) POST,responseXML 包含预期的数据。发出相同的请求,但作为 PUT,对于成功的请求,responseXML 为空。我使用的是 jQuery.ajax,但我也测试了手动实现,结果相同。

var settings = {
    url: '//' + window.location.host + window.location.pathname,
    type: getRequestType(),
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    data: JSON.stringify(parms),
    error: function(jqxhr, status, error) {
        console.log('error');
    },
    success: function(data, status, jqxhr) {
        console.log('success:', data);
    }
};
$.ajax(settings);

我正在使用一个非常简单的服务器请求处理程序,它返回一个简单的 json 格式的字符串。

@require_http_methods(["PUT"])
def proxy_update(request):
    out = {
        'type': 'update',
        'success': True
    }
    return HttpResponse(json.dumps(out), mimetype="application/json")

对此有何解释?

【问题讨论】:

    标签: javascript jquery ajax xmlhttprequest put


    【解决方案1】:

    根据 jQuery 文档,并非所有浏览器都支持所有动词。您使用的浏览器很可能不支持 PUT 动词。尝试其他浏览器。如果故障不是与浏览器有关,那么服务器也可能被配置为忽略 PUT 动词。

    【讨论】:

    • 原来是两种可能原因中的后者。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多