gpt4 book ai didi

objective-c - 子浏览器终止

转载 作者:行者123 更新时间:2023-11-28 22:46:16 25 4
gpt4 key购买 nike

在 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");
}
}
}

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller .' * First throw call stack: (0x154012 0x25fce7e 0x478721 0x479777 0x4797b7 0x6a68 0x67471 0x66c5e 0x67039 0x26106b0 0x1198035 0xd7f3f 0xd796f 0xfa734 0xf9f44 0xf9e1b 0x33be7e3 0x33be668 0x38f65c 0x2366 0x2295) libc++abi.dylib: terminate called throwing an exception (lldb)

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

最佳答案

我明白了!由于 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=test@test.com&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>

关于objective-c - 子浏览器终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13148752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com