2011-03-26 73 views
2

嗨,我試圖在sencha touch中使用Ajax發出POST請求。 我的問題是當我發送請求我的服務器接受它作爲選項請求。 我的代碼是:

var post_json = {usrname:username,password:password};Sencha Touch中的POST請求

 Ext.Ajax.request({ 
      url: 'http://localhost:3000/', 
      method: "POST", 
      params: { 
       user_session: post_json 
      }, 
      success: function(){ 
       alert("sucessful"); 

      }, 
      failure: function(){     
       alert("fail"); 
      } 

     }); 

我該如何解決這個問題?

+1

你是否也在從http:// localhost:3000 /?這可能是一個可能的重複http://stackoverflow.com/questions/1256593/jquery-why-am-i-getting-an-options-request-insted-of-a-get-request – Nicodemuz 2011-03-26 05:16:55

回答

-3

使用JSONP insted的Ajax.Request的

+4

請注意,JSONP將只使用GET而不是POST。 – 2012-04-27 08:55:22

+0

正確,JSONP將不適用於POST。 – 2012-06-26 19:59:40

1

添加參數:

useDefaultXhrHeader : false 

如果不是,GET和POST方法請求將包含X-請求-隨着報頭。我認爲這個頭文件是發送OPTIONS方法請求的原因。

0

這是一個關於CORS.This問題是我web.conf爲asp.net:

<system.webServer> 
<validation validateIntegratedModeConfiguration="false"/> 
<modules runAllManagedModulesForAllRequests="true"/> 
<httpProtocol> 
    <customHeaders> 
    <add name="Access-Control-Allow-Origin" value="*" /> 
    <add name="Access-Control-Allow-Headers" value="X-Requested-With,Content-Type" /> 
    </customHeaders> 
</httpProtocol> 

它的工作在IIS服務器,但在Asp.net開發者服務器也不行。

相關問題