0

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

1
  • PHP is server side and you can't use it to directly get anything from the client side. You have write some client side code to send the data to PHP. If you using jQuery, you probably want to use something in the $.ajax() family. Commented Feb 3, 2012 at 10:14

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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? Thanks
Note $.post in the comment. You should expect value to come from $_POST array, not $_GET.
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?
Could you write this into the question? I just can't read the code this way.
0

You should definitely take some time to learn the concept of AJAX before trying to use it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.