Javascript 如何将多个选定的js变量值传递给php变量

Javascript 如何将多个选定的js变量值传递给php变量,javascript,php,Javascript,Php,我想将selectedDates变量传递到php变量从前端将变量值传递到服务器端的唯一方法是表单提交或使用ajax 因为这两个变量在不同的地方运行,若你们有一个页面,你们不能给php分配一个js变量,因为php在服务器上运行,并且它在页面加载之前就已经运行了 为此,您必须使用ajax或表单提交: .bind('dpClosed',function(e, selectedDates) { console.log('You closed the date picker and the

我想将selectedDates变量传递到php变量

从前端将变量值传递到服务器端的唯一方法是表单提交或使用ajax

因为这两个变量在不同的地方运行,若你们有一个页面,你们不能给php分配一个js变量,因为php在服务器上运行,并且它在页面加载之前就已经运行了

为此,您必须使用ajax或表单提交:

.bind('dpClosed',function(e, selectedDates) {
        console.log('You closed the date picker and the ' // wrap
            + 'currently selected dates are:');
        console.log(selectedDates);
        var ll=document.getElementById('ll');
                        ll.value=selectedDates;

    }
);
现在,在php中,您可以通过以下方式获得:

$.post('the/url/to/post', {selectedDates:selectedDates}, function(response){
  console.log(response);
});

请正确格式化代码在赋值后,您想对“php变量”做什么?
$_POST['selectedDates']