2012-04-10 13 views
0

私はAndroid向けにラップしようとしているPhonegap/Jqueryモバイルアプリを持っていますが、使用しているターゲットSDKはAjax /クロスドメインリクエストを許可していません。 要するに、最新のAndroid 4.0.3(API 15)ではリクエストがうまく動作しますが、Android 2.3.3(API 10)ではリクエストが正常に動作しません。これはGalaxy Tabletと互換性が必要です。 私はphonegapとcantユーザーFirebug/Chrome Webツールでラップされているので、私は実際のエラーを見ることができないので、これをデバッグするのは苦労しています。私はdeveloper.android.comで運が上がらなかった。 http://jquerymobile.com/test/docs/pages/phonegap.htmlにある手順を試しました。 $ .mobile.allowCrossDomainPages = true; $ .support.cors = true。特定のAndroid SDKでAjaxリクエストが機能しない

これも機能しませんでした。 誰かが私を助けることができる、私は他に何を試して知りません。 ありがとう!

ここにコードの簡単な例を示します。それが成功を返すことに注意=真が、「レスポンスはXML要素ではありません」というエラーを打つ:

return $.soapRequest({ 
     url: url, 
     namespace: 'testns', 
     returnJson: false, 
     shortMethod: 'methodname', 
     method: 'longmethodname', 
     params: params || {}, 
     success: function(data) { 
      if (data && data.documentElement) { 
      // hits this on Android SDK 15 
      if (successFn) { 
       return successFn(data.documentElement); 
      } 
      } 
      else { 
      // hits this on Android SDK 10 
      return fail("Response is not an XML element!"); 
      } 
     }, 
     error: function(str) { 
      return fail(str); 
     } 
+0

は、このHTTPを見てみましょうcound .com/2010/03/22/tutorial-getting-android-emulator-working-with-fiddler-http-proxy-tool/ また、これはhttp://jsconsole.com/remote-debugging.htmlでも役立ちます – bmurmistro

答えて

0

は、PhoneGapのをplugginでのHttpConnectionを書いてみます。 //aurir.wordpressを:それはクロスドメイン

httpPlugin.java

package com.android.test; 

import org.apache.cordova.api.Plugin; 
import org.apache.cordova.api.PluginResult; 
import org.apache.cordova.api.PluginResult.Status; 
import org.json.JSONArray; 
import org.json.JSONException; 

import android.util.Log; 

import com.android.connection.HTTPConnect; 

public class HttpPlugin extends Plugin { 
    public final String ACTION_SEND_MESSAGE = "SendCommand"; 
    private HTTPConnect httpConnect; 

    public HttpPlugin() { 
     // TODO Auto-generated constructor stub 
     httpConnect = new HTTPConnect(); 
    } 

    @Override 
    public PluginResult execute(String action, JSONArray arg1, String callbackId) { 
     PluginResult result = new PluginResult(Status.INVALID_ACTION); 
     if (action.equals(ACTION_SEND_MESSAGE)) { 
      try { 
       String message = arg1.getString(0); 
       String receiveString = httpConnect.setURL(message); 
       if(receiveString == null){ 
        //show error result 
        result = new PluginResult(Status.ERROR,"kakaka"); 
       }else{ 
        Log.v("MAN", "data received"); 
        result = new PluginResult(Status.OK); 
       } 
       result = new PluginResult(Status.OK); 
      } catch (JSONException ex) { 
       // TODO Auto-generated catch block 
       result = new PluginResult(Status.JSON_EXCEPTION, ex.getMessage()); 
      } 
     } 
     return result; 
    } 
} 

plugin.xmlファイル

Httppluginの.js

var Httpplugin = function() {}; 

Httpplugin.prototype.post = function (message, successCallback, failureCallback) { 
// navigator.notification.alert("OMG"); 
    return cordova.exec(successCallback, failureCallback, 'Httpplugin', 'SendCommand', [message]); 
}; 

PhoneGap.addConstructor(function() { 
    PhoneGap.addPlugin("http", new Httpplugin()); 
}); 
関連する問題