Can';t获取jQuery post请求以在phonegap中工作
我正在尝试使用jQuery和Ajax将一些formdata发送到phonegap中的远程服务器。我在下面粘贴的代码在我本地机器上的firefox中运行良好,但在我的手机(android)上启动它时就不起作用了。我是否需要修改jquery代码或向其添加一些内容以使其在phonegap中工作 我已经在android清单中添加了互联网权限Can';t获取jQuery post请求以在phonegap中工作,jquery,cordova,Jquery,Cordova,我正在尝试使用jQuery和Ajax将一些formdata发送到phonegap中的远程服务器。我在下面粘贴的代码在我本地机器上的firefox中运行良好,但在我的手机(android)上启动它时就不起作用了。我是否需要修改jquery代码或向其添加一些内容以使其在phonegap中工作 我已经在android清单中添加了互联网权限 <!DOCTYPE HTML> <html> <head> <title>Phonegap
<!DOCTYPE HTML>
<html>
<head>
<title>Phonegap ajax test</title>
<meta name="viewport" content="width=240, height=320, user-scalable=yes, initial-scale=2.5, maximum-scale=5.0, minimum-scale=1.0" />
<script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.0rc2.js"></script>
<link rel="stylesheet" type="text/css" href="css/layout.css" />
<link rel="stylesheet" type="text/css" href="js/jquery.mobile-1.0rc2.css" />
<script type="text/javascript">
$(document).ready(function() {
$('#infoForm').submit(function() {
var postTo = 'http://www.mysite.com/process.php';
$.post(postTo,$('#infoForm').serialize(), function(data) {
alert(data);
});
return false;
});
});
</script>
</head>
<body>
<div data-role="content">
<form method="post" id="infoForm">
<input type="text" name="first_name" id="first_name" value="" placeholder="First Name" />
<input type="text" name="last_name" id="last_name" value="" placeholder="Last Name" />
<input type="text" name="email" id="email" value="" placeholder="Email" />
<button type="submit">Submit</button>
</form>
</div><!-- /content -->
</body>
</html>
Phonegap ajax测试
$(文档).ready(函数(){
$('#infoForm')。提交(函数(){
var postTo=http://www.mysite.com/process.php';
$.post(postTo,$('#infoForm').serialize(),函数(数据){
警报(数据);
});
返回false;
});
});
提交
谢谢 以下代码在Android设备/仿真器中工作,您可以从中使用ajax函数
功能负重(){
警报(“我们正在使用post类型请求调用jquery的ajax函数”);
$.ajax({
网址:'http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml',
数据类型:'application/xml',
超时:10000,
类型:'POST',
成功:功能(数据){
警报(数据);
},
错误:函数(XMLHttpRequest、textStatus、ErrorSprown){
警报(“错误状态:+textStatus”);
警报(“错误类型:“+ErrorSprown”);
警报(“错误消息:+XMLHttpRequest.responseXML”);
}
});
}
Ajax调用
确保您在应用程序中拥有正确的权限
加
到AndroidManifest.xml并添加
<access origin="*"/>
至/res/xml/phonegap.xml
<uses-permission android:name="android.permission.INTERNET" />
<access origin="*"/>