I need to get jquery variable to php variable using Ajax. I would be very grateful if anyone can help me.
我需要使用Ajax获取jquery变量到php变量。如果有人能帮助我,我将非常感激。
$(document).ready(function() {
$('#roomOptions select').change(function() {
var total = 0;
$('#roomOptions select').each(function() {
total+=parseInt($(this).val());
});
$('#roomOptions #roomOptions_total').html(total);
});
});
</script>
2 个解决方案
#1
If you want to pass some data from the client side to the server side, use AJAX, you can choose to send the data as GET or POST
如果要将一些数据从客户端传递到服务器端,请使用AJAX,您可以选择以GET或POST方式发送数据
$.ajax({
url: full_url,
type: 'POST',
data: {"x":1,"y":2}
success: function(result)
{
// do somthing
}
});
#2
You clearly can't. PHP is executed first and then jQuery is executed.
你显然不能。首先执行PHP,然后执行jQuery。
#1
If you want to pass some data from the client side to the server side, use AJAX, you can choose to send the data as GET or POST
如果要将一些数据从客户端传递到服务器端,请使用AJAX,您可以选择以GET或POST方式发送数据
$.ajax({
url: full_url,
type: 'POST',
data: {"x":1,"y":2}
success: function(result)
{
// do somthing
}
});
#2
You clearly can't. PHP is executed first and then jQuery is executed.
你显然不能。首先执行PHP,然后执行jQuery。