【发布时间】:2012-11-08 12:49:57
【问题描述】:
大家好,提前谢谢。 我正在使用 Phonegap 2.1.0。 在白名单中,所有内容都被接受..
**<access uri="*" subdomains="true" />
<access origin=".*" subdomains="true"/>**
我正在使用这个函数从我的大学网络服务器调用一个远程 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!');
}
});
该 php 文件只是出于调试原因,如下所示:
<?php
header('Content-Type: application/json');
$sample = array(
'name'=>'My Name',
'email'=>'my_email@example.com'
);
echo json_encode($sample);
?>
但是 ajax 请求没有发生.. 在 Eclipse 中,当我单击提交时,我不断收到此错误:
JSCallback Error: Request failed with status 0 at file:///android_asset/www/js/cordova-2.1.0.js:3743
更重要的是,我忘了补充,我可以从模拟器打开网址作为链接。它工作正常。
*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>
我已经搜索了我认为几乎整个网络...2天搜索...一切都经过测试.. 非常感谢..
【问题讨论】:
-
http://--/smartphone/login.php是一个有效的 URL 吗?我觉得不像。 -
-- 代表域..like mydomain.example.com.. 如果这被误解了,我深表歉意..
-
尝试在PHP端添加“Access-Control-Allow-Origin: *”HTTP-header,看看是否有效。
-
onon15.感谢您的回复..不幸的是问题仍然存在..
-
刚刚搜索了一下,发现了一些类似错误的问题,都与phonegap 2.1.0有关,是否可以尝试phonegap 2.2.0?
标签: android jquery ajax cordova