【发布时间】:2016-04-22 14:25:28
【问题描述】:
我正在开发一个 Cordova 混合应用程序(目前适用于 android)并使用 InAppBrowswer-Plugin。
我想打开一个网页并使用 post 请求登录(目前在实际的 Android 应用程序中是通过 Java 完成的)。
但不知何故,这不起作用,我不知道为什么。这是我正在使用的代码:
var ref = cordova.InAppBrowser.open("www.thesite.dummy", "_blank", "location=yes");
var postAsString = 'var xhttp = new XMLHttpRequest();'+
'xhttp.open("POST", "'+url+'", true);'+
'xhttp.onreadystatechange = function() {if (xhttp.readyState == 4 && xhttp.status == 200) {alert("it worked")}};'+
'xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");'+
'xhttp.send("username=dummyUser&password=dummyPW")'
console.log(postAsString);
ref.executeScript({"code":postAsString});
如您所见,我还 console.log 我的“postAsString”。如果我复制此字符串并在 www.thesite.dummy 的控制台中执行它,它实际上可以工作,但不能在 InAppBrwoser 中执行
【问题讨论】:
-
在我看来就像 stackoverflow.com/questions/37526321/… 的副本
-
将较新的称为副本会更有意义,但我同意。问题是相同的
标签: javascript cordova post phonegap-plugins inappbrowser