search

Home  >  Q&A  >  body text

How to set the thinkphp5 request type?

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(); 
        }
    }
女神的闺蜜爱上我女神的闺蜜爱上我2763 days ago679

reply all(1)I'll reply

  • 迷茫

    迷茫2017-07-03 11:42:31

    1. Check whether ajax is in post mode
    2. Print all the request data and check again

    reply
    0
  • Cancelreply