I have code which posts a variable to php:
$(document).ready(function() {
$('ul.sub_menu a').click(function() {
var txt = $(this).text();
//console.log("you clicked"+txt);
$.ajax({
type: 'POST',
url: 'thegamer.php',
data: {send_txt: txt},
success: function( data ){
//now echo the data where you want
// for example
//$('#result').html( data );
// or you can see in on firebug
console.log( 'Return:' + data );
}
});
});
});
The php that gets the request:
<?php
include 'dbconnect.php';
$q=$_REQUEST['send_txt'];
//echo $q;
$sql="select imgurl from images where family='shoes'";
$result = mysql_query($sql);
include 'dbclose.php';
?>
How do I return the data back to the ajax request?
Hm, I really suggest you learn more about Javascript, JQuery, AJAX and PHP before you attempt it. It looks like you have no clue how to go about this.
I’ll point you in the right direction starting with W3 Schools (although definitely not the best resource but, it’s a good start):
W3 Schools
Here’s some more information about JQuery from their own JQuery API Documentation
More specifically, the $.ajax function
And here’s how you connect to a Mysql database using PHP
With that being said, this is a general example, using your information, of how you would go about doing an AJAX/server response. I post this so that you might learn something from this code, as it does specifically what you requested:
Javascript
PHP file “thegamer.php”