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.