Hi, I'm trying to use jQuery.post() function to retrieve som data. But i get no ouput.
I have a HTML that dispalys a table. Clicking this table should trigger a jQuery.post event.
My scriptfile looks like this:
jQuery(document).ready(function() {
jQuery('#storeListTable tr').click(function() {
var storeID = this.cells[0].innerHTML; //This gets me the rowID for the DB call.
jQuery.post("../functions.php", { storeID: "storeID" },
function(data){
alert(data.name); // To test if I get any output
}, "json");
});
});
My PHP file looks like this:
<?php
inlcude_once('dal.php');
//Get store data, and ouput it as JSON.
function getStoreInformation($storeID)
{
$storeID = "9";//$_GET["storeID"];
$sl = new storeLocator();
$result = $sl->getStoreData($storeID);
while ($row = mysql_fetch_assoc($result)) {
{
$arr[] = $row;
}
$storeData = json_encode($arr);
echo $storeData; //Output JSON data
}
?>
I have tested the PHP file, and it outputs the data in JSON format. My only problem now is to return this data to my javascript.
- since the javascript is located in teh /js/ folder, is it correct to call the php file by using '../'?
- I don't think I'm passing the storeID parameter correctly. What is the right way?
- How can I call the getStoreInformation($storeID) funtion and pass on the parameter? The jQuery example on jQuery.com has the folloing line: $.post("test.php", { func: "getNameAndTime" } Is the getNameAndTime the name of the function in test.php ?
I really really really need some help on this. I've been stuck for 6 days now :(