Javascript 执行Ajax请求时返回null

Javascript 执行Ajax请求时返回null,javascript,php,jquery,yii2,Javascript,Php,Jquery,Yii2,Ajax请求正在执行,但它返回的不是current_day变量,而是null Js: 控制器: public function actionNextDay() { if (Yii::$app->request->isAjax){ $this->planing_model->curent_day = Yii::$app->request->post('new_curent_day'); return

Ajax请求正在执行,但它返回的不是current_day变量,而是null

Js:

控制器:

public function actionNextDay() {
        if (Yii::$app->request->isAjax){
            $this->planing_model->curent_day = Yii::$app->request->post('new_curent_day');
            return Json::encode($this->planing_model->curent_day);
        }
    }

可能问题在于您正在以JSON的形式发送POST数据,因此您无法通过

Yii::$app->request->post('new_curent_day');
尝试一下,他们已经更新了JSON解析器集,并通过yii获取JSON值


使用浏览器中的Javascript控制台和调试器查看
$('.owl-item.center.slide_day')
包含的内容。让API端点记录它在post变量中得到的内容


变量名中的拼写错误让我担心您可能引用了错误的内容。规划有两个n,电流有两个r。这段代码看起来至少是一致的,但如果我遇到这段代码,我会怀疑current和current混淆了。

检查服务器端实现,找出为什么值变为null?html元素是什么类型。幻灯片\u day?如果它是一个输入字段,请尝试此$('.owl-item.center.slide_day').val();不,这是elementput echo语句,作为echo$this->planning_model->curent_day也验证url'planning/next-day',如果我放入“echo”,那么我会得到异常“parsererror | SyntaxError:JSON.parse:JSON数据的第1行第1列的数据意外结束”选择器是正确的,请求发送的变量看起来像“new_curent_day=26”,但是服务器返回null。根据变量名,我已经检查了所有路径,检查控制器中的$this->planning_model->curent_day是否为空。它的默认值在init()中生成,因此不需要将post变量打印到控制器中,或者是var_dump(Json::encode($this->planning_model->curent_day));
Yii::$app->request->post('new_curent_day');