【问题标题】:Ajax specified as POST but making a GETAjax 指定为 POST 但进行 GET
【发布时间】:2015-09-14 20:38:11
【问题描述】:

AJAX 请求有什么问题?出于某种原因,当我将其指定为帖子时,我的浏览器将其作为 GET 请求接收???

 var body = "<tsRequest><credentials name='username' password='password'><site contentUrl=''/></credentials></tsRequest>";
var url = "http://172.18.74.145/api/2.0/auth/signin";

$.ajax({
    url: url,
    crossDomain: true,
    data: body, 
    type: 'POST',
    contentType: "text/xml",
    dataType: "jsonp",
    success : console.log("too"),
    error : function (xhr, ajaxOptions, thrownError){  
        console.log(xhr.status);          
        console.log(thrownError);
    } 
}); 

我得到错误: GET http://172.18.74.145/api/2.0/auth/signin?callback=jQuery1720699254485778510…%20contentUrl=%27%27/%3E%3C/credentials%3E%3C/tsRequest%3E&_=1442263213074 405(不允许的方法)

如果我将“ajax”更改为“post”,那么 url 就会混乱。

【问题讨论】:

    标签: javascript ajax xml


    【解决方案1】:

    您需要将HTTP方法指定为

    type: 'POST',
    

    而不是像

    method:'POST',
    

    但无论如何你基本上can't 使用 JSONP 和 POST。

    【讨论】:

    • 我改变了它,一个简单的错误但是它仍然在发出 GET 请求。
    猜你喜欢
    • 2013-03-03
    • 1970-01-01
    • 2020-07-07
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    相关资源
    最近更新 更多