Phonegap issue with Ajax Request

不问归期 提交于 2019-12-11 10:07:17

问题


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!


回答1:


@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.



来源:https://stackoverflow.com/questions/34275657/phonegap-issue-with-ajax-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!