I have script and I'd like to know if it's possible the send the value of a variable to $_session,
<s开发者_运维百科cript>
$(function() {
var delivery = 0;
$('#jcart-paypal-checkout').click(function() {
delivery = $('form#delivery2 input[type=radio]:checked').val();
if(!delivery) {
alert('Please choose a delivery option');
return false;
}else {
<?php $_SESSION['shipping'] = ?> delivery;
}
});
});
</script>
I need to send the value of delivery in $_session['shipping'],
thanks
Yes. See How to get JavaScript function data into a PHP variable
For example, use $.get()
:
$(function() {
var delivery = 0;
$('#jcart-paypal-checkout').click(function() {
delivery = $('form#delivery2 input[type=radio]:checked').val();
if(!delivery) {
alert('Please choose a delivery option');
return false;
}
$.get('putInSession.php', { d: delivery });
});
});
This snippet expects a script called "putInSession.php" on the server side, which should check the input parameter "d" and then
$_SESSION["shipping"] = $_GET["d"];
Optionally, you can specify a function that receives the result of the asynchronous request as third parameter of $.get()
.
Yes, this is possible. But you'll have to call the PHP-Script with POST or GET Parameters.
Edit: But I don't think that you can put the variable directly into the session-array.
精彩评论