Can I use jQuery PhoneGap to create ajax calls?

Is it possible to use jQuery ajax calls in PHONEGAP to run a php file that receives records from a database ?! or should i use javascript ajax? What's the best way to achieve this in PHONEGAP?

+6
source share
1 answer

You can certainly use jQuery Ajax features in PhoneGap applications. Here is a demo:

- JavaScript in the application -

$('#some_page_id').bind('pageshow', function () { $.get('http://domain.com/path/to/script.php?get_param=value', function (data) { $(this).find('div[data-role="content"]').append(data); }); }); 

- PHP on the server -

 if (isset($_GET['get_param']) && $_GET['get_param'] == 'value') { $query = mysql_query("SELECT * FROM some_table WHERE some_col='something'", $db_handle); if (mysql_affected_rows() > 0) { while ($row = mysql_fetch_assoc($query)) { echo "<div>" . $row['some_other_col'] . "</div>"; } } else { echo "No Data Found"; } } 

The above example will request a PHP script on the server each time the "#some_page_id" page is displayed, and add the data captured by the <div data-role="content"> . You can also use .html(data) instead of .append(data) to replace HTML, rather than adding to it.

UPDATE

I found this in the jQuery Mobile documentation, which gives excellent information on how to call $.ajax() in PhoneGap applications: http://jquerymobile.com/demos/1.0/docs/pages/phonegap.html p>

+12
source

Source: https://habr.com/ru/post/894947/


All Articles