Tuesday 15 September 2015

javascript - No result from a getJSON in cordova -



javascript - No result from a getJSON in cordova -

i have problem cordova app. have php page mini rest service json output , want utilize result in app.

php page:

<? header("content-type:application/json"); function response($status, $status_message, $data){ header("http/1.1 $status $status_message"); echo $data; } $link = mysqli_connect("db4free.net", "luigi", "nzor4csv4", "usl5"); if (mysqli_connect_errno()) { response(400, "failed connect mysql", mysqli_connect_error()); } if( !empty($_get['prestazioni']) ){ //make response using database $result = mysqli_query($link,"select distinct `ppasez_descrizione` `prestazioni`"); $arr = array(); while($obj = mysqli_fetch_assoc($result)) { $arr[] = $obj; } $message= json_encode($arr); response(200, "lista prestazioni", $message); } else { //invalid request response(400, "invalid request", null); } ?>

html page:

<html> <head> <meta charset="utf-8" /> <script type="text/javascript" src="cordova.js"></script> <link rel="stylesheet" href="js/libs/jquery-mobile/jquery.mobile.css" /> <script type="text/javascript" src="js/libs/jquery/jquery.js"></script> <script type="text/javascript" src="js/libs/jquery-mobile/jquery.mobile.js"></script> <script type="text/javascript" src="js/mainjs.js"></script> <script> $(document).ready(function(){ $.support.cors=true; $.mobile.allowcrossdomainpages = true; $("button").click(function(){ $.getjson('http://www.****.it/provaluigi/index.php?prestazioni=""',function(data){ $.each(data, function(i, dat){ $("ul").append("<li>"+dat.ppasez_descrizione+"</li>"); }); $('ul').listview('refresh'); //if $("list") $("list").listview("refresh); }); }); }); </script> <title> prestazioni </title> </head> <body> <section id="page1" data-role="page" data-fullscreen="true"> <div class="content" data-role="content"> <ul data-role="listview" data-filter="true" data-filterplaceholder="cerca prestazione"> </ul> </div> </section> </body>

this code work perfect on local domain can't see outcome 1 time inserted in cordova.

as can see insert:

$.support.cors=true; $.mobile.allowcrossdomainpages = true;

and

<access origin="*"/>

in config.xml permit cross domain request.

also when test in chrome "ripple extension" notice 2 error:

failed load resource http://localhost:8383/centri%20usl/config.xml

and.

failed load resource: net::err_empty_response http://localhost:8383/centri%20usl/cordova.js

so there errors in linking of cordova bundle utilize netbeans it's automatic. can help me find error?

thanks everyone

according phonegap documentation

the whitelisting rules found in res/xml/cordova.xml

try adding rule res/xml/cordova.xml

javascript php jquery json cordova

No comments:

Post a Comment