How do you call a PHP function that is in a different file from a JavaScript function?
I have a JavaScript function that recieves a variable from an onClick function. The variable is an id that I will use to retrieve data from MySQL database. The variable is then passed on to a PHP function that will access the database to get the data and return back to my JS function for display, but it does not seem to be working. How can I get it to work? I am using CodeIgniter PHP.
Here is my code:
JavaScript in a different file called divUpdate.php
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
base_url = '<?= base_url();?>index.php/';
</script>
<script type="text/javascript">
function changeDiv(venueID){
//document.getElementById('venue_description').innerHTML=venueID;
$.get(base_url+'home/get_venue_description/' + venueID,
function(data) {
$('venue_description').html(data);
});
}
</script>
Where the onClick function calls the JavaScript above:
<li><a href="#self" class="menulink" class=&{ns4class};
onClick="changeDiv(\''. $venue_details->VenueID . '\')">;
Function below is called from JavaScript above in divUpdate.php. The function below is also in in the model- venue_model.php
function retrieveData($venueID){
$query = $this->db->query("SELECT * FROM venue WHERE VenueID = '$venueID' ");
return $query;
}
Then, in the controller home.php I have a function that the JavaScript uses to pass the id that will then be used by the model to retrieve the data from the database
function get_venue_description($venueID){
echo $this->venue_model->retrieveData($venueID);
}
For some reason the code in the JavaScript divUpdater.php doesn't work. It looks correct but doesn't work.