Javascript Yii控制器中的“$”POST[“var”存在问题

Javascript Yii控制器中的“$”POST[“var”存在问题,javascript,php,json,post,yii,Javascript,Php,Json,Post,Yii,我在控制器上的$_POST[“var”]上遇到问题。它似乎是空的。如何接收文本文件中键入的字符串 查看 <?php Yii::app()->clientScript->registerCoreScript("jquery"); ?> <script type="text/javascript"> $(document).ready(function(){

我在控制器上的$_POST[“var”]上遇到问题。它似乎是空的。如何接收文本文件中键入的字符串

查看

<?php Yii::app()->clientScript->registerCoreScript("jquery"); ?>
                <script type="text/javascript">
                $(document).ready(function(){
                        $("#hhmm").change(function(){
                        $.ajax({
                      url: "<?php echo CController::createUrl('reqTest01Loading'); ?>",
                                data: $(this).serialize(),
                                type: "post",
                                dataType: "json",
                                success: function(data) {
                                      if (data.status === 'failure') {
                                            $('#impatto').val('Error request failed.');
                                         } else {
                                                 $("#impatto").html(data.total);     
                                         } 

                                }
                        });
                        });

                });
                </script>
控制器上的规则

public function actionReqTest01Loading() {

    $result = array("total" => $_POST['hhmm'], "status"=>"OK");
            echo CJSON::encode($result);
}
array('allow',  // allow all users to perform 'index' and 'view' actions
            'actions'=>array('reqTest01Loading','index','view','admin'),
            'users'=>array('@'),
        ),


提前感谢

这是因为您没有告诉ajax调用发送参数

尝试:


使用CVarDumper::Dump($\u POST,100,true);在控制器中查看通过ajax发送的所有数据。您正在尝试$\u POST['hhmm'],这是错误的,因为ajax没有设置html元素的id。您可以尝试$\u POST['data']打印($\u POST)并检查其返回的内容使用
cvdumper::Dump($\u POST,100,true)时,我没有任何响应
打印($\u POST)
它只是空白。通过将hhmm更改为数据的方式,没有任何响应,只有:{“total”:null,“status”:“OK”}try
var\u dump(file\u get\u contents('php://input'));你好,TNC,我像你说的那样更新了代码,甚至控制器看起来也像:
公共函数actionReqTest01Loading(){var_dump(Yii::app()->request->getPost('data');$result=array(“total”=>60+$\u POST['hhmm',“status”=>“OK”);echo CJSON::encode($result)}
var_dump(Yii::app())->请求->获取帖子(“数据”)
在注释了我添加了60+**的行之后禁止ajax调用,因此在视图中我只能看到60,但不要求和**hhmm就像没有$\u POST[“hhmm”]再次感谢您可以获得
$(此)。在
Yii::app()->request->getPost('data')
中序列化()
;检查
$(this).serialize()
中的值
$(this).serialize()
中的值为空。这怎么可能呢???也许我会尝试用Autocomplete实现一个不同的解决方案,我无法理解为什么这个值为null。
    $.ajax({
    url: "<?php echo CController::createUrl('reqTest01Loading'); ?>",
       data: {data:$(this).serialize()},
       type: "post",
       dataType: "json",
       success: function(data) {
           if (data.status === 'failure') {
              $('#impatto').val('Error request failed.');
           } else {
              $("#impatto").html(data.total);     
           } 

        }
   });
public function actionReqTest01Loading() {
    // var_dump(Yii::app()->request->getPost('data'));
    $result = array("total" => Yii::app()->request->getPost('data'), "status"=>"OK");
    echo CJSON::encode($result);
}