繁体   English   中英

在jQuery .post中检索$ _POST

[英]Retrieving $_POST in jQuery .post

我有一些选择值。

当选择一个选项时,我需要在jQuery中使用.post将选定的值发送到PHP函数以获得PHP上的$_POST变量。

然后,我可以使用变量评估PHP上的条件。

我使用CakePHP 2创建URL。

将发布网址numberOptionnumberOption变量。

                $( "#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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM