3

私は Firefox 用の拡張機能を作成していpage-modます。モジュールを使用して、以下を含む JavaScript ファイルを実行しています。

function handleServerResponse() {

   if (xmlHttp.readyState == 4) {
     if(xmlHttp.status == 200) {
        //some code
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}

var xmlHttp = new XMLHttpRequest();
var txtname = document.getElementById("txtname");
xmlHttp.open("POST","http://localhost:8080/Jelly/GetStuff",true);
xmlHttp.onreadystatechange  = handleServerResponse;
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send("url=" + document.URL);

代わりにIPアドレスを使用しても、取得xmlhttp.status==0し続けます。何か案は?200localhost

4

1 に答える 1

2

コンテンツ スクリプト コードはクロスドメイン リクエストを実行できません。代わりに Request モジュールを使用してみてください。

https://addons.mozilla.org/en-US/developers/docs/sdk/1.1/packages/addon-kit/docs/request.html

別のスクリプトでコードを記述し、page-mod を使用してページに挿入する代わりに、アドオンの main.js スクリプトでリクエストを実装できます。

于 2011-09-15T17:40:57.540 に答える