This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19848|Reply: 1

[Jquery] jQuery intercepts the results returned by Ajax

[Copy link]
Posted on 2021-2-23 17:16:45 | | | |
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.

ASP.NET WebApi uses MessageHandlers to unify the return interface model format
https://www.itsvse.com/thread-9442-1-1.html

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.
jquery listens for all ajax request completion statuses
https://www.itsvse.com/thread-9470-1-1.html

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)




Previous:[turn] SQL Server SQL Count
Next:jQuery gets the URL parameter value extension
 Landlord| Posted on 2023-6-22 10:30:10 |
The ajax-hook for web development intercepts all XMLHttpRequest requests
https://www.itsvse.com/thread-10616-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com