[英]spring boot mvc ajax call with a loading
I have a spring boot mvc application. 我有一个Spring Boot MVC应用程序。 My requirement is when i hit a url like this localhost:8080/myproject/getData
我的要求是当我点击类似localhost:8080 / myproject / getData的网址时
It should show a loading gif and do a ajax call to the spring mvc controller and return the result "ok" to the caller. 它应该显示一个加载的gif并对spring mvc控制器进行ajax调用,并将结果“确定”返回给调用者。 Could anyone give a sample code or some idea on implementing it ?
任何人都可以给出示例代码或实现示例的想法吗?
You have to make 2 controllers. 您必须制作2个控制器。
@Controller
will be responsible for returning the page with loading gif (it can be Thymeleaf, JSP, or whatever), that HTML "view" returned by MVC @Controller
will contain JavaScript with your AJAX implementation (jQuery, AngularJS, or whatever), that will make an AJAX call to your @RestController
, requesting JSON/XML data (the URL has to be different eg "/myproject/api"). @Controller
将负责返回加载了gif(可以是Thymeleaf,JSP或其他任何东西)的页面,由MVC @Controller
返回的HTML“视图”将包含具有AJAX实现的JavaScript(jQuery,AngularJS或其他任何东西),这将对您的@RestController
进行AJAX调用,以请求JSON / XML数据(URL必须不同,例如“ / myproject / api”)。
Then on your success method you will replace the loading GIF with your data from @RestController
(the result "ok"). 然后,在成功方法上,您将用
@RestController
的数据替换正在加载的GIF(结果为“确定”)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.