Why does success() only return json data when used in tp5.0.7 controller?
暖暖橙
暖暖橙 2019-06-17 16:35:46
0
1
1171

Hello everyone, I have been learning tp5 recently and encountered a problem today when implementing the exit function. The following is part of the code:

Front end

<a href="{:url('index/user/logout')}">退出</a>


Controller

public function logout()
{
    //清空session
    session(null);
    //提示退出成功,并跳转到登录页
    $this->success('恭喜!退出成功!','index/user/login');
}


Desired result:
The smiling face showing the success method of tp

Then it prompts "Congratulations! Exit successfully!

Three-second countdown

The page in front of you becomes the page of url('index/user/logout')

Actual result:

{"code":1,"msg":"恭喜!退出成功!","data":"","url":"\/index\/user\/login.html","wait":3}


---------------------------------- --------------------------
That's it, unexpected results.

Know success() and error () will automatically determine whether the current request is in ajax mode.

The 'default_return_type' set in the application's configuration file => 'html'

and no other header-related things are set

I don’t know why it is judged as ajax method here. I hope someone who knows can explain it. I would be grateful!

暖暖橙
暖暖橙

reply all(1)
暖暖橙

Not very active!

It’s been a long time.

In fact, the problem has been solved long ago.

There is no problem with the code.

is a problem with a js file introduced.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template