javascript - getjson jquery doesn't work in phonegap android -
javascript - getjson jquery doesn't work in phonegap android -
i'm trying retrieve json info local server in phonegap android app. i've set submit input data.i using method $.ajax in jquery that. problem when click submit, nil displayed page refreshed. don't see how prepare this.
could please help me? in advance.
(ps: json returned right , i've changed access in config.xml)
here total code :
<!doctype html> <html> <head> <title>application test</title> <script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script> <link href="css/jquery.mobile-1.0rc1.min.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.6.4.js"></script> <script src="js/jquery.mobile-1.0rc1.min.js"></script> <script> document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() { } </script> <script type="text/javascript" language="javascript"> $(document).ready(function(){ $('#testform').submit(function(){ $('#content').html("<b>chargement...</b>"); $.ajax({ url: "http://localhost/projects/api/getallcategorie.php" }).done(function(data){ $("#content").html('<p> id: ' + data.categories[0].id + '</p>'); log('erreur'); }).fail(function(){ alert("erreur!!"); $("#content").html('erreur'); log('erreur'); }); homecoming false; }; </script> </head> <body> <img src= "css/images/logo-annuaire-mayotte.png"> <ul data-role="listview" data-filter="true" data-filter placeholder="rechercher..." data-inset="true"> <li><a href="#">restaurants</a></li> <li><a href="#">bâtiments</a></li> <li><a href="#">numéros utiles</a></li> </ul> <form id='testform'> <div><input type="submit" id="driver" value="synchronisation" /></div> </form> <div id="content"> </div> </body> </html>
if want connect localhost php file utilize port number(working me) or ip address of actual scheme
http:// localhost:8080/projects/api/getallcategorie.php,(for emulator) http:// 10.0.2.2/projects/api/getallcategorie.php
close document ready function
$(document).ready(function(){ $('#driver').click(function(event){ event.preventdefault(); // prevent default action of form $('#content').html("<b>chargement...</b>"); $.ajax({ url: "http://localhost:8080/projects/api/getallcategorie.php", datatype:"json", beforesend:function(){ alert("request going send now");// place loader }, success:function(data){ $("#content").html('<p> id: ' + data.categories[0].id + '</p>'); log('erreur'); }, error:function(xhr, status, error){ alert(xhr.responsetext); $("#content").html('erreur'); log('erreur'); } }); homecoming false; }); });
html : replace form tag input tag
<div><input type="button" id="driver" value="synchronisation" /></div>
javascript android jquery json cordova
Comments
Post a Comment