[英]Retrieving $_POST in jQuery .post
我有一些选择值。
当选择一个选项时,我需要在jQuery中使用.post
将选定的值发送到PHP函数以获得PHP上的$_POST
变量。
然后,我可以使用变量评估PHP上的条件。
我使用CakePHP 2创建URL。
将发布网址numberOption
到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
变量?
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.