OK, well this:
Code:
<script type="text/javascript">
$('div.bekijkitem').click(function() {
var text = $(this).text();
var variableToSend = text;
$.post('meebekijken.php', {variable: variableToSend});
alert (variableToSend);
});
</script>
Does nothing until someone clicks on one of the bekijkitem div elements. So anything it does cannot show up on this page unless it's via javascript alone, or unless the page is reloaded after it happens. I don't know what's on meebekijken.php, but it should receive the value. It cannot communicate back to this page though unless you use it's response from the AJAX call. It can set values in the session (perhaps), or drop a PHP cookie (more likely), and certainly can enter a value into a flat file or a database. Once it does one of those things, that value will be available in future PHP page loads and future PHP script runs.
To make this a little clearer, when you do:
Code:
$.post('meebekijken.php', {variable: variableToSend});
all you are doing is running the code on meebekijken.php with the POST value of 'variable' set to whatever variableToSend was at that moment. It doesn't change the anything on this page. Further, only the server side code on meebekijken.php will do anything. Any HTML or javascript on that page will be ignored in the current setup. If you were to do something with the response from meebekijken.php*, then both server side code and text/HTML on meebekijken.php could do something, but any javascript would still be ignored, as the page isn't loaded into the browser, just requested from the server.
*By having a return function for the $.post request, something like:
Code:
$.post('meebekijken.php', {variable: variableToSend}, function(data){alert(data);});
Then if you got anything back from meebekijken.php, you could use it right away via javascript on the current page.
Usually this is what's done. We send send data out to a PHP script, it can set something in a database or elsewhere for later use in PHP, and can also send the same information, or even something else (like a confirmation) back to the current page for immediate use by javascript on the current page.
Bookmarks