There is a problem with thinkphp5.1 ajax updating data, please give me some advice
圐圙
圐圙 2018-05-19 09:19:41
0
3
1979

After using AJAX to submit the data to be updated, I want to know what data is received in the controller. Is it the data in my table? Or is it the data for judgment?


## public function update(Request $request){

$status=0;

$id = $request->get ('id');

$data = $this->request->param();

// dump($data); What is the amount of data here? Let’s take a look. It doesn’t work with dump, and it can’t be executed?

$a=Db::name('dh')->where('id',$id)->update($data);

if (!$a ) {

              $message = 'Failed to join. ';

} else {

              $status = 1;  

          session('admin', $a); Join successfully! ';

} }  

  return ['status' => $status, 'message' => $message];

}

--------------------------------------------- -------------------------------------

圐圙
圐圙

reply all(2)
PhpNewer

$data is all the data of the form submitted by your front end through ajax. This is an associative array. tp5 uses json by default. Are you using dump output to verify the data in $data?

updata() Shouldn’t the sql statement of mysql be executed here? How can I execute $data directly?

圐圙

$name= $this->request->param('name');
$add= $this->request->param('add');
$time= $this->request->param('update_time');
$a = Db::name('dh')
->where('id',$s)
- >data(['name' => $name,
'add'=>$add,
'update_time'=>$time
])
->update( );

Do you have to ask me to write like this? What if I have many fields to change?

  • reply Then I change it to the above, won’t it work? If there are many fields, do we have to receive them one by one and write them in?
    圐圙 author 2018-05-20 13:33:14
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template