2012-05-14 10 views
2

私はSencha Touch 2を使用してアプリケーションを作成していますが、Webからアクセスするとうまく動作します。問題は、iPhone用にビルドし、ローカルURL(../services/myservice.php)からリモートURL(http://remoteurl.com/services/myservice.php)に変更したときです。Sencha Touch 2でJsonPを使用してフォームを送信するには?

私は、クロスドメインエラー入門:

**XMLHttpRequest cannot load http://example.com/services/userRegister.php?_dc=1336972603884. Origin http://localhost is not allowed by Access-Control-Allow-Origin.** 

をそして私はJSONP使用してフォームを送信する方法があればお聞きしたいと思いますので、私はもうこの問題はありません。ここで

は、フォームの私のコードです:

Ext.define('RegistroMovil.view.Register',{ 
extend: 'Ext.form.Panel', 
xtype: 'register', 
requires:[ 
    'Ext.form.FieldSet', 
    'Ext.form.Email' 
], 
config: { 
    title: 'Register', 
    iconCls: 'user', 
    url: 'http://example.com/proys/congreso/services/userRegister.php', 
    items: [ 
    ... 

そしてフォームを送信するボタンのコード:

{ 
      xtype: 'button', 
      text: 'Register', 
      handler: function(){ 
       this.up('register').submit({ 
        success: function(f, a){ 
         alert('Your id: ' + a.id); 
         f.reset(); 
        } 
       }); 
      } 
     }, 

はどうもありがとうございました!

答えて

1

cross-origin resource sharingポリシーのため、上記のエラーが発生しています。

submitボタンのtapボタンでは、Ext.Ajax.request();を使用できますが、同じエラーが表示されることもあります。

例えば

Ext.Ajax.request({ 
    values : paramValues // values from form fields.. 
    url: '.../test.php', 

    success: function(response) { 
    console.log(response.responseText); 
    } 

    failure: function(response) { 
    console.log(response.responseText); 
    } 
}); 

だから、それはフォームsubmitを処理するためにExt.util.JSONP.request()を書く方が良いでしょう。

Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of the running page, you must use this class, because of the same origin policy.

例えば

Ext.util.JSONP.request({ 
     params: paramValues // values from form fields.. 
     url: '.../test.php', 
     callbackKey: 'callback', 
     scope: 'this', 
     success: function(response) { 
     console.log(response.responseText); 
     } 

     failure: function(response) { 
     console.log(response.responseText); 
     } 
}); 
関連する問題