I'm working with the plugin ParamQuery grid and to the data source need to get json data, this what I want to do with $. getJson (...) {}, but I have a PHP class called data.php, which contains a method called GetData other InsertData, DeleteData, (CRUD-using PDO), GetData returns the infromacion as json. The problem is how to call the function from jquery?
the code I use is:
data.php
<?php
class Data {
private $db = NULL;
const DB_SERVER = "localhost";
const DB_USER = "root";
const DB_PASSWORD = "usbw";
const DB_NAME = "musicstore";
public function __construct() {
$dsn = 'mysql:dbname=' . self::DB_NAME . ';host=' . self::DB_SERVER;
try {
$this->db = new PDO($dsn, self::DB_USER, self::DB_PASSWORD);
} catch (PDOException $e) {
throw new Exception('Connection failed: ' . $e->getMessage());
}
return $this->db;
}
public function getData() {
$statement = $this->db->prepare("Select * from Customer");
$statement->execute();
if ($statement->rowCount() > 0) {
echo json_encode($statement);
}
return false;
}
}
?>
functionjquery.js
$.getJSON('Data.php', function(data) {
var obj = {};
obj.width = 1000;
obj.height = 400;
obj.colModel = [{title: "Rank", width: 150, dataType: "integer"},
{title: "Company", width: 200, dataType: "string"},
{title: "Revenues ($ millions)", width: 200, dataType: "float", align: "right"},
{title: "Profits ($ millions)", width: 200, dataType: "float", align: "right"}];
obj.dataModel = {data: data};
$("#grid_array").pqGrid(obj);
});