Rbac does not have permission to return how to determine whether to jump to the page or return ajax

Source: Internet
Author: User
In the background process, thinkphp's rbac is used to check permissions in each baseController. When there is no permission, the page with no permission is output, but if there is a button, after clicking the button, the front-end page does not have any feedback. Only F12 Developer Tools can... problems encountered during background Creation
Use the rbac of thinkphp.
Check permissions in each baseController
When no permission is available, the page with no permission is output.
However, if it is a button, the front-end page does not have any feedback if you click it. Only F12 developer tools can be seen

Therefore, how can we get the correct return method after we find that there is no permission? If there is a page for him to enter the page without permission, if there is a button for him to return ajax, a box with no permission will pop up.

Reply content:

Problems encountered during background processing
Use the rbac of thinkphp.
Check permissions in each baseController
When no permission is available, the page with no permission is output.
However, if it is a button, the front-end page does not have any feedback if you click it. Only F12 developer tools can be seen

Therefore, how can we get the correct return method after we find that there is no permission? If there is a page for him to enter the page without permission, if there is a button for him to return ajax, a box with no permission will pop up.

Determine whether the request is an Ajax request or a normal page request based on the HTTP request header. If the request is a normal one, the system directly jumps to the login page. If the request is an Ajax request (With X-Requested-With: XMLHttpRequest) HTTP status 401 is returned, or similar to common data that can express the Unlogged-on status. My processing is {status: 1, message: '', data: [...]}. in this data structure, the front-end determines whether the data is successfully obtained based on the status of the returned data, and then further processes the encapsulated data.

RestController has the response () method to return json, or write a method to return json by yourself.
For example, return:

{Error: 1, msg: "No permission to access xxx "}

The front end can judge data. error.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.