jquery - how with phonegap to retrieve data from remote php/mysql server -


i trying build ios app using phonegap

i want data remote server display in phonegap. on server have php/mysql, on client side have phonegap , developing app in jquery mobile.

i know need use jsonp have problem.

on server side developed simple app.

i have two php pages.

first php page - list.php, display list of navigation (home, us, gallery). second php page - text.php display info list.php. example page display "about us" information, gallery display images , text information...

on client side have 2 html pages.

list.html - page successfuly connect list.php using jsonp.

on list.html - pull data remote server , display navigation (home, us, gallery). page display navigation list, nothing special.

listtext.html - problematic html page, don't know how solve.

when user open list.html in browser, can click on home button or on button (i make link in format: listtext.html?id=1) but don't know how parse on listtext.html. suppose need have get, don't know how do.

so on listtext.html need see detailed information home, us, gallery.

i attached code - listtext.html page - javascript because problem sure here

    $(document).ready(function(){      var output = $('.nesa');      $.ajax({         url: 'http://www.example.com/text.php',          datatype: 'jsonp',         jsonp: 'jsoncallback',         timeout: 5000,         success: function(data, status){             $.each(data, function(i,item){                    var final= item.id;                   output.append(final);              });          },         error: function(){             output.text('there error loading data.');         }     });   }); 

this text.php page:

    <?php  //header('content-type: application/json'); 

include 'config.php';

$con = mysql_connect($dbhost, $dbuser, $dbpass) or die ("could not connect: " . mysql_error()); mysql_select_db($dbname, $con);

$id=$_get['id']; // collecting data query string

$sql = "select * ios id=$id"; $result = mysql_query($sql) or die ("query error: " . mysql_error());

$records = array();

while($row = mysql_fetch_assoc($result)) { $records[] = $row;

}

echo $_get['jsoncallback'] . '(' . json_encode($records) . ');';

?> 

i sure text.php ok, encoded in jason. got jsonp output text.php when click mysite.com/text.php?id=1 got info "home" page in jason format.

but problem in javascript (jquery), because don't know how parse.

so me how parse jason in javascript.

thank you.

try one:

success: function(data, status){    var jsondata = json.parse( data ); } 

and can use jsondata examnple length jsondata.length


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -