2012-10-30 184 views
0

在JavaScript中調用多個函數以獲取用戶名/電子郵件地址/密碼。當一切都好的時候去goForLogin()並打開一個chrildbrowser。我得到的連接錯誤(見下圖):子瀏覽器終止

首先我的代碼:

 function goForLogin(emailaddress, value){ 
      var xmlhttp; 
      xmlhttp=new XMLHttpRequest(); 
      xmlhttp.open("POST","http://dev.server.com/test/login",true); 
      xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
      xmlhttp.send("email=" + emailaddress + "&password=" + value); 

      xmlhttp.onreadystatechange=function() 
      { 
       if (xmlhttp.status==200) 
       { 

        value = null; 
        window.plugins.childBrowser.showWebPage('http://dev.server.com'); 
       } else { 
        alert("FAILED"); 
       } 
      } 
     } 
由於未捕獲的異常「NSInvalidArgumentException」,原因

*終止應用程序:「應用程序試圖把 模態啓動控制「。 *第一擲調用堆棧:(0x154012 0x25fce7e 0x478721 0x479777 0x4797b7 0x6a68 0x67471 0x66c5e 0x67039 0x26106b0 0x1198035 0xd7f3f 0xd796f 0xfa734 0xf9f44 0xf9e1b 0x33be7e3 0x33be668 0x38f65c 0x2366 0x2295)的libC++ abi.dylib:終止叫做拋出異常(LLDB)

最新的Cordova和Childbrowser,Xcode 4.4版本。

回答

2

我明白了!由於xmlhttp.onreadystatechange聲明,childBrowser將在此腳本中打開三次。這是不允許的蘋果 - 對不起,我忘了爲什麼 - 所以我打了個電話。它看起來像這樣:

我的javascript:

function some_function2(url, callback) { 
     var httpRequest; // create our XMLHttpRequest object 
     if (window.XMLHttpRequest) { 
      httpRequest = new XMLHttpRequest(); 
     } else if (window.ActiveXObject) { 
      // Internet Explorer is stupid 
      httpRequest = new 
      ActiveXObject("Microsoft.XMLHTTP"); 
     } 
     httpRequest.onreadystatechange = function() { 

      // inline function to check the status 
      // of our request 
      // this is called on every state change 
      if (httpRequest.readyState === 4 && 
      httpRequest.status === 200) { 
      callback.call(httpRequest.responseXML); 
      // call the callback function 
     } 
     }; 
     httpRequest.open('POST', url, true); 
     httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
     httpRequest.send("[email protected]&password=1"); 
     } 


function call() { 
    // call the function 
    some_function2("http://dev.server.com/account/login/", function() { 
       console.log(this); 
       callChildBrowser(); 
       }); 
       console.log("this will run before the above callback"); 

} 


function callChildBrowser(){ 
    window.plugins.childBrowser.showWebPage('http://dev.server.com'); 
    } 
在我的html

最後:

<button id="butten" onclick="call()">WORKS</button>