大家好,并且提前好.我正在使用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 …Run Code Online (Sandbox Code Playgroud)