2015-09-14 22 views
-1

AJAX請求有什麼問題?出於某種原因,我的瀏覽器將它作爲GET請求來挑選,當我將它指定爲一個帖子時?將Ajax指定爲POST但發出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 /憑證%3E%3C/tsRequest%3E & _ = 1442263213074 405(不允許的方法)

如果我將「ajax」更改爲「發佈」,那麼URL會搞砸。

回答

0

您需要爲

type: 'POST', 

,而不是指定的HTTP方法

method:'POST', 

但無論如何,你基本上can't使用JSONP與POST。

+0

我改變了這個,簡單的錯誤,但它仍然在發出GET請求。 – Ben

+0

@Ben將鏈接添加到JSONP線程。 – wero