The jQuery JavaScript is up and running, but needs a PHP file to handle the Ajax data submitted by the rating script. This will be done with PHP in the receiver you defined in your JavaScript, named „rating.php“ in the „public/includes“ folder. It’s important to put this PHP file in your public folder, because if you pointed your webserver to „public“, anything outside (subfolders of  your document root) can’t be accessed by JavaScript.

Create the „rating.php“, and add the following lines:

require_once('bootstrap.php'); // Setup Zend Framework Environment
header("Cache-Control: no-cache");
$rating = new Mylib_Rating_Controller();
$score = $rating->setRatingById($_GET['id'], $_GET['val']); // rate object and get scores
echo Zend_Json::encode($score); // send response array in JSON format

The setRatingById passes the values from your JavaScript to the (soon to be created) controller, and receives the updated values from your (soon to be created) database. When I started out using jQuery in combination with Ajax, I was kind of afraid to find it difficult… but it really is that easy 😉

Next up: The rating controller