You can use AJAX to get JSON data from your own site. For example, this code is used to get the username of a user by its identifier. JS in PhoneGap app:
function getUsername(){
var id = document.getElementById("textbox").value;
$.ajax({
url: "https://www.example.com/json_read?id=" + id,
type: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data.username);
},
error: function () {
alert("Error");
}
});
}
PHP on your website:
<?php
require 'db.php';
$id = $_GET['id'];
$sql = $mysqli->query("SELECT * FROM users WHERE id='$id'");
$result = $sql->fetch_assoc();
$object->username = $result['username'];
$json = json_encode($object);
echo $json;
?>
Make sure that you use it only in PhoneGap so that no one can see your source code and play with your database :)
source
share