gnn*_*pls 11 ajax jquery android cordova
大家好,并且提前好.我正在使用Phonegap 2.1.0.白名单中的一切都被接受了..
**<access uri="*" subdomains="true" />
<access origin=".*" subdomains="true"/>**
Run Code Online (Sandbox Code Playgroud)
我正在使用此函数从我的大学Web服务器调用远程php文件:
var postData = $(this).serialize();
$.ajax({
type: 'POST',
url: 'http://--/smartphone/login.php',
dataType : 'json',
data: postData,
success: function(data){
alert("good");
},
error: function(){
alert('problem!');
}
});
Run Code Online (Sandbox Code Playgroud)
php文件只是出于调试原因,如下所示:
<?php
header('Content-Type: application/json');
$sample = array(
'name'=>'My Name',
'email'=>'my_email@example.com'
);
echo json_encode($sample);
?>
Run Code Online (Sandbox Code Playgroud)
但是ajax请求没有发生..在eclipse中,当我点击提交时我不断收到此错误:
JSCallback Error: Request failed with status 0 at file:///android_asset/www/js/cordova-2.1.0.js:3743
Run Code Online (Sandbox Code Playgroud)
更重要的是,我忘了添加,是我可以打开网址作为模拟器的链接.它工作正常.
*HTML代码:*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" charset="utf-8" src="js/cordova-2.1.0.js"></script>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<title>Smart Greenhouse</title>
</head>
<body>
<div id="container">
<img src="css/images/smart_green_house.png" class="logo" alt="l1ogo" />
<form id="login_form" class="first_display" >
<label class="title"> E-mail:</label>
<input id="1" type="email" class="input" size="45" name="email" />
<label class="title"> password:</label>
<input id="2" type="password" class="input" size="45" name="password" />
<input id="3" class="submit_type" type="submit" value="login" />
</form>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我搜索了我几乎整个网络... 2天搜索...一切都经过测试.. Thanx很多..
最后,经过 4-5 天的搜索......对我来说有些东西解决了......我只是return false在 ajax 回调之后添加。我将代码更改如下:
$('form').submit(function(e){
if (password_ok==1 && email_ok==1)
{
var postData = $(this).serialize();
$.ajax({
type: 'POST',
url: 'http://mysite.xx.x/smartphone/login.php',
dataType : 'json',
data: postData,
success: function(data){
alert(data);
},
error: function(){
alert('error!');
}
});
}
else
{
e.preventDefault();
if (email_ok==2)
{
$("#1").css("border-color","red");
$("#1").css("background-color","#FFD8CE");
}
if (password_ok==2)
{
$("#2").css("border-color","red");
$("#2").css("background-color","#FFD8CE");
}
}
return false;
});
Run Code Online (Sandbox Code Playgroud)
现在唯一的问题是成功后它不会重置页面..而是一次一步......
| 归档时间: |
|
| 查看次数: |
9634 次 |
| 最近记录: |