Requirements: Intercept all Ajax request results, and if the return status code is 404, you will be redirected to the login screen.
You can also get the model data for a unified response, and according to the returned fields, if there is an error, an error message will pop up, and the callback method will no longer be executed.
Trying to use ajaxcomplete can't be blocked, just getting the response content, and not preventing the callback method from being called, ajaxsuccess is not tested, and it's probably about the same.
The hyperlink login is visible.
The hyperlink login is visible.
Writing method 1:
Test code:
When trying to modify the original data, the callback method obtains the modified data, and the API returns the data as follows:
{"success":true,"message":"aa","data":{"name":"itsvse.com"}} Modify the original data, only pass the data data of the json object to the callback method, ignoring the success and message attributes, the jQuery code is as follows:
The effect is as follows:
Writing method 2:
The essence of writing method 1 and writing method 2 is the same, for simplicity, it is recommended to write method 1.
(End)
|