2

私はチタン製アクセラレーターファミリーを初めて使用します。また、誰かが以前に同じ問題を投稿したかどうかもわかりません。見つからなかったのでここに投稿します。

1 つのモバイル アプリケーションを開発しています。私のアプリケーションでは、ローカル環境でホストされている 1 つの Web サービスを呼び出そうとしていますが、常にステータス コード 0 とエラー メッセージ「ホストに到達できません」で応答を返しています。そのため、リモート ロケーションにデプロイした Web サービスに何らかの問題があるはずだと考えました。そのため、Twitter などの他の Web サービスを呼び出そうとしましたが、同じです.. :( Twitter Web サービスの呼び出し中にもエラーが発生します。

クロスドメイン ポリシーの問題もチェックします。そのため、Web サービスのサーバーにもルールを設定しようとしましたが、うまくいきませんでした。以下は、私が使用しているコード スニペットと環境の詳細です。

  1. アプリケーションの種類:モバイル
  2. チタン SDK: 2.1.4 GA
  3. デバイス: Web ブラウザ
  4. ホスト オペレーティング システム: Windows 7
  5. チタン スタジオ:チタン スタジオ、ビルド: 2.1.2.201208301612

私が呼び出しているサンプル Web サービスのファイルは、次の場所にあります。

  1. http://db.tt/XoSCujux (api.php)
  2. http://db.tt/bJG2A5XT (Rest.inc.php)
  3. http://db.tt/Hxt6Oojx (.htaccess)

コード:

//declare the http client object
            var xhr = Titanium.Network.createHTTPClient();

            //this method will process the remote data
            xhr.onload = function() { 
                //check to see if we are refreshing the data via our 
                //pull and release mechanism

                //create a json object using the JSON.PARSE function
                result = JSON.parse(this.responseText);

                Ti.API.info(result);
                console.log(result);

                var msgTitle = "data:";
                var msgText = result;
                var alertBox = Ti.UI.createAlertDialog({
                            title: msgTitle,
                            message: msgText
                        });
                alertBox.show();    
            };  


            //this method will fire if there's an error in accessing the remote data
            xhr.onerror = function(e) {  
                //log the error to our titanium developer console 
                Ti.API.error(this.status + ' - ' + this.statusText);
                console.log(this.status + ' - ' + this.statusText); 



                var msgTitle = "Error : " + this.status;
                var msgText = "Error Text : " + this.statusText;
                var alertBox = Ti.UI.createAlertDialog({
                            title: msgTitle,
                            message: msgText
                        });
                alertBox.show();    

                 Ti.API.debug("STATUS: " + this.status);
                    Ti.API.debug("TEXT:   " + this.responseText);
                    Ti.API.debug("ERROR:  " + e.error);
                    alert('There was an error retrieving the remote data. Try again.' +  e.error);
            };  

            //open up the recipes xml feed
            xhr.open("POST", "http://127.0.0.1/rest_example/api.php?rquest=locations");

            //finally, execute the call to the remote feed
            xhr.send();

どんな助けでも本当に感謝しています。

4

0 に答える 0