我正在android上製作移動應用程序,並使用phonegap,移動jquery ajax codeigniter和mysql。我在登錄過程中遇到問題。我的AJAX請求一直失敗。我在註冊過程中使用相同的東西,它可以工作。它奇怪的。這是我的代碼上的login.html上的PhoneGap:使用Phonegap-AJAX登錄移動應用程序
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv=」Content-Type」 content=」text/html; charset=utf-8>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input[type=text]").val('');
document.addEventListener("deviceready", init, false);
function init() {
$('a[id^="submitButton"]').on('click',function(){
$("#submitButton",this).attr("disabled","disabled");
//$("#loginForm").on("submit",function() {
u = $("#username").val();
p = $("#password").val();
if(u!='' && p!='') {
$.ajax({
url:'http://****.dyndns-home.com/health/index.php/health_login?username='+u+'&password='+p,
dataType:'json',
success:function(data, textStatus, jqXHR)
{
$.mobile.changePage("menu1.html");
if(data.status==1) {
localStorage.setItem("username", u);
localStorage.setItem("password", p);
$.mobile.changePage("menu1.html");
$("input[type=text]").val('');
}
if(data.status==0){
alert("Wrong username or password!");
$("input[type=text]").val('');
}
},
error: function(jqXHR, textStatus, errorThrown){
alert('AJAX request failed');
}
});
}
else{
alert("You must enter a username and password");
}
return false;
});
}
});
</script>
</head>
<body>
<div data-role="page">
<div data-role="header" >
<h2>Login</h2></div>
<div data-role="content">
<form id="loginForm">
Username: <input type="text" id="username" value="" name="username"/>
Password:<input type="text" id="password" value="" name="password"/>
<a href="forget.html" > Ξέχασες τον κωδικό ή το όνομα χρήστη;</a><br>
<a href="index.html" data-role="button" data-transition="turn" data-inline="true" data-icon="back" >Back</a>
<a href="" id="submitButton" name="submitButton" data-role="button" data-inline="true" data-theme="b" data-icon="forward">Είσοδος</a>
</form>
</div>
<div data-role="footer" data-position="fixed"><h2></h2></div>
</div>
</body>
</html>
此外,當我對鉻和mozzila運行我的login.html作爲一個Web應用程序我沒有問題,Ajax請求的成功!我使用api level 15(android 4.0.3)在eclipse上運行這個應用程序。
告訴我,如果你需要我的register.html代碼。
你覺得怎麼樣? 我正在尋找解決這個問題現在2天,我什麼都做不了。
謝謝!
你沒有說它是如何工作的。點擊事件沒有被觸發? Ajax電話沒有出去? –
問題在於ajax請求。 Ajax調用失敗,它顯示錯誤消息。正如我之前所說,我在我的register.html頁面使用相同的ajax請求與不同的url和數據,它的工作正常!另外當我運行我的網站login.html(鉻,mozzila)它的作品。所以我的php-mysql是正確的。 – user1637624