Hey guys,
check out the code below
$('#checkout').click(function() {
$.ajax({
type: 'GET',
url: 'index.php?route=payment/check/confirm',
data{id:'this is a data string'},
success: function() {
location = '<?php echo $continue; ?>';
}
});
});
This is attached to an onclick() event handler for a button. Can someone tell me how to access this data from the script that it has been sent to (index.php?route=payment/check/confirm). I haven’t really mixed php and js much so any ideas?
thanks
An AJAX request like that is essentially… ok imagine Javascript is firing up its own browser, going to that url, getting the info (, closing the browser) and then storing that in a variable. (this isn’t the case but it might help you to make more sense out of it)
Treat it in PHP like it’s a normal request - because, essentially, that’s what it is.
Hi Silv,
As Jake says, in php you handle it like a normal request BUT there is one major difference: You don’t output a html page. Instead you only output data instead which the javascript then uses. In order to recognise this in your script you might use something like &mode=ajax in your url and check for it in your script.
You access the $_GET stuff just as you would normally.