I have file that is supposed to pass the id of a link to using the ajax post method to a php file so that a div on my webpage updates. But nothing happens so i think the class is not being passesd. Can anyone see the problem.
blog.js
$('a.bloglink').click(function(e) {
// first stop the link to go anywhere
e.preventDefault();
// get the class of the link
var linkClass = $(this).attr("class");
//get the text of the link by converting the clicked object to string
var linkText = new String(this);
// the value after the last / is the category ID
var categoryValue = linkText.substring(linkText.lastIndexOf('/') + 1);
// put the post parameters into 'params' to pass through the AJAX post request
var params = {};
params[linkClass] = categoryValue;
// send the category ID to the showproducts.php script using jquery ajax post method
// send along a category ID
// on success insert the returned text into the chosen div
$.post('../inc/blogchoice.php', params, function(data) {
//display returned data and page links in chosen div (.blog)
$('.blog').html(data);
});
});
blogchoicephp
include 'connect.php';
if(isset($_POST['bloglink'])){
// cast the category to integer (just a little bit of basic security)
$id = (int) $_POST['bloglink'];
$q = "SELECT * FROM blogs WHERE id=$id";
$result = $link->query($q);
// this will be the string that you will return into the product-data div
$returnHtml = '';
// construct the html to return
while($row = mysqli_fetch_array($result)) {
$returnHtml .= $row['content'];
}
}
// display the html
echo $returnHtml;
Thanks for looking..........