I've a div <div id="single-home-container"></div> that displays a value from a jquery script. Can I use php to get that value so I can pass it into a mysql query?
Thanks
2 Answers
yes this is called AJAX. There are all kinds of AJAX functions in jQuery, in your case I think post would work great. This is the standard example from the jQuery doc:
$.post('ajax/test.php', $('#single-home-container').html(), function(data) {
$('.result').html(data);
});
Take a look here.
4 Comments
Ian Jarvis
Thanks Florian. I then placed
$result = $_GET['result']; echo $result; on my footer.php to see the results but to no avail. I changed the file path to /footer.php and also tried absolute URL but again to no avail. Any idea? ThanksJ0HN
Note
$.post in the comment. You should expect value to come from $_POST array, not $_GET.Ian Jarvis
Thanks, I've tried that to to no avail.My code is as follows: ` $(document).ready(function(){ $.ajaxSetup({cache:false}); $(".locationID").click(function(){ var post_id = $(this).attr("rel"); //alert($(this).attr('rel')); $("#single-home-container").html("loading..."); $("#single-home-container").html(post_id); $.post('/footer.php', $('#single-home-container').html(), function(data) { $('.result').html(data); }); return false; }); });
And on footer.php $result = $_POST['result']; echo 'Result: '.$result;` nothing shows?Florian Rachor
Could you write this into the question? I just can't read the code this way.
$.ajax()family.