2012-08-16 30 views
1

我在使用我的opera擴展連接到java應用程序時出現問題 我已經在chrome a中使用了此擴展。Opera擴展xmlhttp.send();錯誤

這是在popup.html在javascritp代碼

function AtribuirID(){ 

    if (window.XMLHttpRequest) 
    { 
     // code for IE7+, Firefox, Chrome, Opera, Safari 
     xmlhttp=new XMLHttpRequest(); 
    } 

    xmlhttp.onreadystatechange = function() 
    { 
     if (xmlhttp.readyState==4 && xmlhttp.status==200) 
     { 
      var texto = xmlhttp.responseText; 
      var splitagem=texto.split("(user)"); 
      localStorage.setItem('ID',splitagem[0]); 
      localStorage.setItem('Auxiliar',splitagem[1]); 
     } 
    } 

    xmlhttp.open("GET","http://localhost:10002?z=AtribuirID",true); 
    xmlhttp.send(); 
} 

的問題是,我得到一個錯誤未捕獲的異常:拋出:DOMException:NETWORK_ERR在xmlhttp.send(),我不能在訪問我的應用假設是服務器部分的java。 我已經把網絡=「公私」在config.xml但它沒有工作

+0

也許,當調用AtribuirID時,Java applet還沒有準備好(尚未完全加載)。 – Jay 2012-08-20 04:57:28

+0

java應用程序已準備就緒,因爲我已經在chrome中做了這個擴展並且它可以工作。 – user1268879 2012-08-20 07:45:55

回答

7

在config.xml文件中加入這一行:<access origin="*" subdomains="true"/>允許任何域的HttpRequest前</widget>標籤,這解決了問題,如果問題依然存在,在opera的opera選項卡中打開「opera:config」並選擇「Users Prefs」並選中「Allow File XMLHttpRequest」並重新啓動。如果有問題,我可以給你我的opera擴展工作正常......

+0

tnks工作得很好的ALEX ORTIZ – user1268879 2012-09-04 11:59:33

+0

太好了。樣式表和tilemaps(在cocos2d-html中)現在可以正確加載。謝謝! – 2014-02-08 10:56:12