【发布时间】:2016-04-01 23:20:53
【问题描述】:
我在第一次使用 PhoneGab,但出了点问题......
当我在 之前收到“数据”(来自 PHP 的 json 响应时,我很喜欢使用 window.location.href 方法Ajax 请求(跨域))。
但是当我在我的手机(Android)上测试这个想法时,重定向不起作用......
ps:在网络浏览器上通常一切都很好。
有人发现问题了吗?
这是我的代码:
<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>
【问题讨论】:
-
您知道Google and Apple frown on apps 都是网站包装器吗?此外,最佳做法是将网页放在设备上。
-
杰西是对的。这就是为什么 Google 和 Apple 添加了“添加到主屏幕”选项,用户可以在其中将您的网页直接添加到他们的主屏幕。
标签: javascript php jquery ajax phonegap-build