我有一些带有一些值的选择。
当选择一个选项时,我需要在jQuery中使用.post
将所选值发送到PHP函数以获取PHP上的$_POST
变量。
然后我可以使用该变量来评估PHP上的条件。
我使用CakePHP 2创建一个URL。
将帖子网址绑定到numberOption
变量。
$( "#selectFilter" ).change(function() {
var numberOption = "<?php echo $this->Html->url(array('action' => 'returnNumberOption/' ));?>" +
"/" + $( "#selectFilter option:selected" ).val();
$.post(numberOption, function(data){
console.log("Here is the number value of the select "+data);
var phpVariable = "<?php echo $_POST?>"//THIS DONT WORK!
});
});
使用此代码我收到unexpected identifier
错误。
问题
如何在jQuery $_POST
调用中获取$.post
变量?
答案 0 :(得分:0)
var url = "<?php echo $this->Html->url(array('action' => 'returnNumberOption/' ));?>";
var value = $( "#selectFilter option:selected" ).val();
$.post(url,{data: value})
.done(function(data){
console.log("Here is the number value of the select "+data);
var phpVariable = "<?php echo $_POST?>"//THIS DONT WORK!
});
<?php
public function returnNumberOption() {
if ($this->request->is('post')) {
$data = $this->request->data;
}
}