0

私は sencha touch2 を初めて使用し、sencha touch2 で外部 Web サービスを使用したいと考えています。この原因のコードを書きましたが、アラート メッセージが機能していません! コンソールで、この XMLHttpRequest cannot load http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld?_dc=1336466078991&method=Helloworld&format=jsonのようなエラーが表示されます。

オリジンhttp://localhost:49692は Access-Control-Allow-Origin で許可されていません。app/view/Blog.js?_dc=1336466047687:27応答ステータス:- 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)
                        }
                   });
                }
            }
          }
        ]
    }
});
4

3 に答える 3

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);
                    }
               });
于 2012-05-08T09:18:27.683 に答える
0

私はあなたの問題の解決策を見つけたと思います。

まず、 Nicholas C. Zakas によるCross-Origin Resource Sharing を使用した Cross-domain Ajaxに関する優れた記事を読んでください。この Cross-domain Cross-Origin リソース共有の問題を明確に説明しています。

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

JSONP または「パディング付き JSON」は、ベース JSON データ形式を補完するものであり、ページがプライマリ サーバー以外のサーバーから JSON を要求し、より有意義に使用できるようにする使用パターンです。

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);
     }
});

そしてそれは今うまくいくはずです!

于 2012-05-08T10:25:53.173 に答える