1. Question:
I need to write a judgment on the controller page. If the data is passed by ajax, the database will be searched. Otherwise, the page will be displayed directly.
I have been unable to obtain data using the condition request()->isAjax(). I don’t know if it is correct. Could you please help me, thank you~
2.Code
<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
class User extends Controller{
//新增用户
public function add_user(){
if (request()->isAjax()){
$data = input('post.');
p($data);die;
}else{
return $this -> fetch();
}
}
1. Check whether ajax is in post mode
2. Print all the request data and check again