2012-05-08 16 views
0

私はsencha touch2を初めて使用しています。私はsencha touch2で外部Webサービスを使用したいと考えています。このXMLHttpRequestのようなエラーを与えるコンソールでは、http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld?_dc=1336466078991&method=Helloworld&format=jsonをロードできません。sencha touch2で外部Webサービスを使用する方法

Origin http://localhost:49692 is not allowed by Access-Control-Allow-Origin. app/view/Blog.js?_dc=1336466047687:27Response Status:- 0

問題の原因を教えてください。

Ext.define("GS.view.Blog", { 
    extend: 'Ext.navigation.View', 
    xtype: 'blog', 
    config: { 
     title: 'WebService', 
     scrollable: true,  
     items: [ 
      { 
      xtype: 'button', 
      text: 'Press Me', 
      height: 40, 
      width: 200, 
      listeners: { 
       tap: function() { 
//     alert("Hi Welcome To Sencha"); 
        Ext.Ajax.request({ 
         method: 'GET', 
         url: 'http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld', 
         params: { method: 'Helloworld', format: 'json' }, 
         success: function (response, request) { 
          alert('Working!') 
          alert(response.responseText) 
          console.log('Response:-' + response.responseText) 
         }, 
         failure: function (response, request) { 
          alert('Not working!') 
          console.log('Response Status:- ' + response.status) 
         } 
        }); 
       } 
      } 
      } 
     ] 
    } 
}); 

答えて

0

私が思う

 Ext.data.JsonP.request({ 

        url: 'http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld', 
        params: { method: 'Helloworld', format: 'json' }, 
        success: function (response) { 
         alert('Working!') 
         console.log(response); 
        }, 
        failure: function (response) { 
         alert('Not working!') 
         console.log(response); 
        } 
       }); 
+0

あなたが送信したものと同じコードを使用しましたが、Uncaughtのようなコンソールで同じエラーが発生しました。TypeError:未定義のメソッド 'request'を呼び出せません。 –

0

あなたはJSONデータに変換プレーンテキストのためにeval関数を使用することができます - :

はここに私のコードです、ありがとうございました。

var newObject=eval('('+response.responseText+')'); 
+0

k.iはWebサービスを使用できません。エラーが発生しました。メッセージが来ない... pbmは何ですか... –

+0

コンソールでエラーが見つかりましたか?はいの場合はエラーを表示させてください。 –

+0

何も表示していません....空白でした –

0

このコードを試してみてください、私はあなたの問題への解決策を考え出しました。

まず、Nicholas C. ZakasによってCross-domain Ajax with Cross-Origin Resource Sharingのこの優秀な記事を読んでください。このクロスドメインクロスソースリソース共有の問題を明確に説明しています。

あなたの場合、JSONPリクエストを行う必要があります。

JSONP or "JSON with padding" is a complement to the base JSON data format, a usage pattern that allows a page to request and more meaningfully use JSON from a server other than the primary server.

JSONP is an alternative to a more recent method called Cross-Origin Resource Sharing .

あなたがする必要があるのは、このようなExt.util.JSONP.request()呼び出しを行い

Ext.util.JSONP.request({ 
    url: 'http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld', 
    params: { 
     method: 'Helloworld', 
     format: 'json', 
     callback: 'callback', 
    }, 

    success: function (response) { 
      alert('Working!') 
      console.log(response); 
    }, 
    failure: function (response) { 
      alert('Not working!') 
      console.log(response); 
    } 
}); 

、それが今で動作するはずです!

+0

私は送信したものと同じコードを使用しましたが、このようなコンソールでエラーが発生しました_Uncaught TypeError:undefined_の 'request'メソッドを呼び出せません。上記のコードは動作していない、あなたは問題が何か私に電話できますか?ありがとうございました。 –

+0

通常、エラーは ''メソッドを呼び出すことはできません 'X'は未定義です.'ということは、 'X'を呼び出そうとしているオブジェクトが存在しないことを意味します。だから、 'Ext.util.JSONP'要求に必要なファイルを含めていることを確認してください... –

+0

私ははっきり分かりませんでした。すでに必要なファイルをすべて提供しています。 ** Uncaught TypeError:未定義のメソッド 'request'を呼び出せません**。何がコーディングの問題です。 –

関連する問題