嘿:)我在使用 Spring Boot 和 AJAX 时遇到一些问题。目前我有按钮,我必须单击才能转到另一个页面(下一页,上一页)。我想用 ajax 请求替换它,以在向下滚动时加载我的页面。我是 Spring 框架的新手,有人可以向我解释一下实现它的方法吗?
@Controller
public class HomePageController {
@Autowired
private AirUserService service;
@Autowired
private OfferService offerService;
@RequestMapping(value = {"/", "/homepage"} , method=RequestMethod.GET)
public ModelAndView home(ModelAndView modelAndView , @RequestParam(name="p" , defaultValue="1") int pageNumber) {
Page<Offer> page = offerService.getPage(pageNumber);
modelAndView.getModel().put("offerpage", page);
modelAndView.setViewName("app.homepage");
return modelAndView;
}
最佳答案
在客户端站点中,您需要一个脚本
,一旦页面向下滚动到底部,它将触发ajax
调用。这个 ajax 调用将为您提供更多数据。
下面是 jQuery 脚本
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()){
alert("bottom!");
// getData();
}
});
如果您的页面中有任何基于模板
的实现,那就更好了。
关于javascript - Spring Boot 和 AJAX 用于向下滚动时加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43695388/