0

これは、スタック オーバーフローに関する私の最初の投稿です。そのため、規則を尊重し、できるだけ明確にしようとします。

序章 :

このプロジェクトでは、ローカル Web サーバーで Web アプリを作成しようとしています。私のプロジェクトは2つの部分に分かれています:

  1. 実Webサーバーにリクエストを送信するローカルWebサーバー(Same Originポリシーを解決するためのソリューションです)
  2. ビューである Android Web アプリ。問題が発生した場所です。

ajax リクエストを使用してサーバーと通信しようとすると、エラーINVALID_STATE_ERR: DOM Exception 11が発生しました。ただし、Firefox(Apacheを使用)で実行している場合、この問題はありません。

ローカル Web サーバー:

Web サーバーは、Web アプリと Web サーバーの間でデータを保管または送信するだけです。

ウェブアプリ:

初期化

私のAndroidアクティビティでは、次のようにWebアプリを開始しています:

 webview = new WebView(this);

 MyJavaScriptInterface myJavaScriptInterface = new MyJavaScriptInterface(this);
 webview.addJavascriptInterface(myJavaScriptInterface, "AndroidFunction");

 // set settings
 webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
 webview.getSettings().setJavaScriptEnabled(true);
 webview.getSettings().setAppCacheEnabled(false);
 webview.setHorizontalScrollBarEnabled(false);
 webview.setVerticalScrollBarEnabled(false);
 if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) // 16
 {
// yourwebview, i use phonegap here
   webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
    webview.getSettings().setAllowFileAccessFromFileURLs(true);
    }

    // start
    uri = new URI("http://127.0.0.1:"+LocalServer.RECORDING_PORT+"/index.html");
    webview.loadUrl(uri.toString());

アヤックス

私のwebappにデータを保存するために、私は基本的なことをしていますXMLHttpRequest(これも試しましJQueryたが、メッセージは出ませんでした)

function saveObject(in_strAction, in_oData, fctCallback)
{

    var l_strURL = 'http://127.0.0.1:8888/api/' + in_strAction;
    var xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=function()
    {
        try // line 46
        {
            console.log ("xmlhttp.readyState="+xmlhttp.readyState+" && xmlhttp.status="+xmlhttp.status);
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                fctCallback(xmlhttp.responseText);
            }
        }
    }

    xmlhttp.open("POST",l_strURL,true);
    xmlhttp.send();
}

反応

Web アプリが受け取る回答は json で、ヘッダーは Web サーバーによって作成されます。

4

1 に答える 1

0

問題が解決しました

INVALID_STATE_ERR: DOM Exception 11無効なステータスの読み取り中に例外が発生しました:

function saveObject(in_strAction, in_oData, fctCallback)
{

    var l_strURL = 'http://127.0.0.1:8888/api/' + in_strAction;
    var xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=function()
    {
        try
        {
            // Don't read status here (on state 1 exception will be up)
            console.log ("xmlhttp.readyState="+xmlhttp.readyState);
            if (xmlhttp.readyState==4)
            {
                // Status can be read here.
                console.log ("xmlhttp.status="+xmlhttp.status);
                if (xmlhttp.status==200)
                {
                    fctCallback(xmlhttp.responseText);
                }
            }
        }
    }

    xmlhttp.open("POST",l_strURL,true);
    xmlhttp.send();
}
于 2013-06-10T10:59:50.790 に答える