PhoneGap的1.5.0安卓科尔多瓦AJAX JSON [英] PhoneGap 1.5.0 Android Cordova AJAX JSON
问题描述
我一直在努力,现在通过一个Android PhoneGap的应用程序发送一个AJAX请求在一天运行最新的1.5.0 PhoneGap的。我已经尝试了GET,POST,AJAX,从展台的jQuery包(不是jQuery Mobile的)的getJSON请求。在一个标准的浏览器所有的工作原理,但没有从应用程序的工作。
这是我最新的jQuery的AJAX code
$。获得(
http://www.fakedomainname.com/ajax/user_login.php,
$('#emailLoginForm')。序列化()
功能(JSON){
//console.log(json);
警报(json.status);
},
JSON
);
这是我的PHP code
头(访问控制 - 允许 - 产地:'。$ _ SERVER ['HTTP_ORIGIN']);
标题(缓存控制:无缓存,必重新验证');
头('过期:星期一,1997 05:00:00 GMT 7月26日);
标题(内容类型:应用程序/ JSON);
$输出['状态'] = 99; //新用户
回声json_en code($输出);
我已经加入clearCache到我的AndroidManifest.xml
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
super.clearCache();
super.loadUrl(文件:///android_asset/www/index.html);
}
我已经加入这个/res/xml/cordova.xml
<*获得原产地= />
还有什么我缺少什么?我不能让GET jQuery的要求,成功地警惕什么?我已经确定缓存被清除。我已经列入白名单在我的PHP文件的头,在我cordova.xml文件中的跨域问题。我输了,有没有人成功地创建了一个AJAX调用新的PhoneGap 1.5.0?
错误是我的错。我还击中的URL包括的检查,看看是否用户代理是一个移动装置的功能。如果是这样,将呼叫重定向到域/网站,我要求的移动友好的版本。其结果是从来没有返回我的JSON值。我删除了移动设备的检查功能,所有的我的设置上面完全正常工作。的
super.init();
super.clearCache();
您缺少的init
。尝试将上述。
I have been trying to send an AJAX request for over a day now through an Android PhoneGap App running the latest 1.5.0 PhoneGap. I have tried a GET, POST, AJAX, getJSON request from the stand jQuery package (not jQuery Mobile). All of it works in the a standard browser but nothing is working from the App.
Here is my latest jQuery AJAX Code
$.get(
'http://www.fakedomainname.com/ajax/user_login.php',
$('#emailLoginForm').serialize(),
function(json) {
//console.log(json);
alert(json.status);
},
'json'
);
Here is my PHP code
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
$output['status'] = 99; //new user
echo json_encode($output);
I have added clearCache to my AndroidManifest.xml
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.clearCache();
super.loadUrl("file:///android_asset/www/index.html");
}
I have added this to /res/xml/cordova.xml
<access origin=".*"/>
What else am I missing? I cannot get the GET jQuery request to successfully alert anything? I have made sure cache is cleared. I have whitelisted the cross domain question in header of my php file and in my cordova.xml file. I am lost, has anyone successfully created an AJAX call with the new PhoneGap 1.5.0?
The error was my fault. The URL I was hitting also included a function that checked to see if the user-agent was a mobile device. If so it would redirect the call to a mobile friendly version of the domain/site I was requesting. As a result my json value was never being returned. I removed the mobile device check function and all of my settings above worked perfectly fine.
super.init();
super.clearCache();
You are missing the init
. Try adding the above.
这篇关于PhoneGap的1.5.0安卓科尔多瓦AJAX JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!