Ajax请求的Phonegap问题 [英] Phonegap issue with Ajax Request
问题描述
我有一个用PHP开发的web应用程序,它以JSON格式返回数据。
我创建了一个HTML来读取这些数据,在Android屏幕上显示它们。 p>
可通过Phonegap Desktop在网络上工作,通过连接智能手机。
但是当我通过构建生成APK。
我的JS代码:
$。support.cors = true;
$(document).ready(function(){
$ .ajax({
url:'http://zieltecnologia.com.br/mobile/js_bolsa.php',
type:'GET',
crossDomain:true,
cache:false,
success:function(data){
alert(data);
}
error:function(){
alert('error');
}
});
});
我的PHP代码:
echo json_encode($ sXml-> Papel [1] ['Codigo']);
我的CONFIG电话号码:
< plugin name =com.indigoway.cordova.whitelist.whitelistpluginspec =1.1.1source =pgb/>
< allow-navigation href =*/>
< access origin =*/>
< allow-intent href =*/>
我尝试过使用JSONP,但没有通过Phonegap Desktop本地连接。
感谢!
@leonardogeranio,
这是一个常见的错误。
首先,您不能使用通过 Phonegap Desktop App 创建的文件,并在 Phonegap Build 上使用这些文件。您可以使用 Phonegap CLI 而不是 Build 来使用这些文件。它的工作方式不同。您需要从自己的样板或已知的工作样板开始。
这里是一个让你入门的 Phonegap - Generic-Boilerplate7
以下博文将为开发工作你熟悉你所需要的,但不要用它来生产。
PhoneGap的HTML Boilerplate
使用两者作为参考。
如果您正在寻找更好的例子。这是另一篇博客文章:
混合HTML5 Boilerplates :打破旧版链接
如果您想要解释使用 Phonegap桌面应用程序的问题,我
最后,如果你的JavaScript代码位于 index.html
,您需要使用 CSP
以及 cordova-plugin-whitelist
插件。请勿使用您在本页上列出的插件。
最好的运气。
I have a web application developed in PHP that returns data in JSON format.
I created a HTML to read this data shows them on the Android screen.
Works on the web, via Phonegap Desktop works by connecting smartphone.
But when I generate the APK via build.phonegap.com, it does not.
My JS code:
$.support.cors = true;
$(document).ready(function(){
$.ajax({
url: 'http://zieltecnologia.com.br/mobile/js_bolsa.php',
type: 'GET',
crossDomain: true,
cache: false,
success: function(data) {
alert(data);
},
error: function(){
alert('error');
}
});
});
My PHP code:
echo json_encode($sXml->Papel[1]['Codigo']);
My CONFIG the phonegap:
<plugin name="com.indigoway.cordova.whitelist.whitelistplugin" spec="1.1.1" source="pgb" />
<allow-navigation href="*" />
<access origin="*" />
<allow-intent href="*" />
I've tried using JSONP worked but not connecting locally by Phonegap Desktop.
Grateful!
@leonardogeranio,
This is a common mistake.
First, you can NOT use files created with Phonegap Desktop App and use those files on Phonegap Build. You can use those files with Phonegap CLI, but not Build. It works differently. You need to start with your own boilerplate, or a known working boilerplate.
Here is one to get you started Phonegap--Generic-Boilerplate7
The following blog post will work for development and make you familiar with what you need, but do not use it for production.
An HTML Boilerplate for Phonegap
Use the both as a reference.
If you are looking for more good examples. Here is another blog post:
Hybrid HTML5 Boilerplates: Breaking the Chains of Legacy
If you'd like an explanation, on the issues with using Phonegap Desktop App, I can write a blog post on this.In the meantime, use another boilerplate.
Finally, if you javascript code sits in the index.html
, you will need to use the CSP
along with the cordova-plugin-whitelist
plugin. DO NOT USE THE PLUGIN YOU HAVE LISTED ON THIS PAGE.
Best of Luck.
这篇关于Ajax请求的Phonegap问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!