[英]Redirect with Ajax / JQuery / PhoneGab
I use PhoneGab for my firstime , and something wrong... 我将PhoneGab用于我的第一时间 ,但出现了问题...
I woodlike use the window.location.href method when I receive 'data' ( json response from PHP before an Ajax request(cross domain)). 当我收到“数据”(来自Ajax请求(跨域)之前来自PHP的 json响应)时,我喜欢使用window.location.href方法。
But when I test this think on my mobile(Android), the redirection doesn't work... 但是当我在我的手机(Android)上测试这种想法时,重定向不起作用...
ps: everything is usually fine on web browser. ps:通常在网络浏览器上一切都很好。
Does anyone see the problem? 有人看到这个问题吗?
That's my code : 那是我的代码:
<html> <head>
<title>Ajax Cross-Origin</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<link rel="stylesheet" href="css/bootstrap/css/bootstrap.min.css" /> </head>
<body>
<div id="body-inside" data-role="page">
<div class="logo-inside">
<a href="index.html" class="connexionForm">
<span id="arrowLeft" class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span>
</a>
</div>
<div class="titre"><h1 id="inscTitle">Inscription</h1></div>
<form class="FormInscription" method="POST">
<label>Nom</label>
<input type="text" name="nom" id="nom" placeholder="nom"/>
<label>Prénom</label>
<input type="text" name="prenom" id="prenom" placeholder="prénom"/>
<label>Email</label>
<input type="email" name="email" id="email" placeholder="xyz@email.com"/>
<label>Mot de passe</label>
<input type="password" name="password1" id="mdp1" placeholder="xxx123"/>
<label>Confirmer votre mot de passe :</label>
<input type="password" name="password2" id="mdp2" placeholder="xxx123"/>
<button id="saveLogin" >
Suivant
</button>
</form>
</div>
<script type="text/javascript">
function redirect(){
window.location.href = "inscription_suite.html";
} $(function() {
$( '#saveLogin' ).click(function(){
var nom = $("#nom").val();
var prenom = $("#prenom").val();
var email = $("#email").val();
var mdp1 = $("#mdp1").val();
var mdp2 = $("#mdp2").val();
$.post( "http://webawards.io/data.php",{
firstname : nom,
lastname : prenom,
mail : email,
pass1 : mdp1,
pass2 : mdp2
},function( data ) {
if(data!=="false"){
sessionStorage.setItem("id", data);
redirect();
} else if(data=="false"){
alert("Une erreur semble s'être produite, veuillez réessayer");
}
});
});
}); </script>
</body> </html>
The updated cordova version doesn't allow you to redirect via javascript. 更新的cordova版本不允许您通过javascript重定向。 You need to follow the instructions in order to make the javascript redirect work.
您需要按照说明进行操作,以使javascript重定向正常运行。
Add the " Cordova Whitelist Plugin " in your config.xml 在您的config.xml中添加“ Cordova白名单插件 ”
<gap:plugin name="cordova-plugin-whitelist" spec="1.1.0" />
Or simply 或者简单地
<plugin name="cordova-plugin-whitelist" spec="1.1.0" />
Try putting the following in your config.xml 尝试将以下内容放入config.xml中
<content src="index.html" />
is the path to your HTML file inside the source directory. 是源目录中HTML文件的路径。
<access origin="*" />
will allow you to redirect to any of the external page using JS. 将允许您使用JS重定向到任何外部页面。 If you want to restrict your app to just a single domain then use it like this.
如果您想将应用程序限制为一个域,则可以像这样使用它。
<access origin="http://yourdomain.com" />
At the end, put the following intents 最后,提出以下意图
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.