如何在 Spring MVC 中使用 AJAX 渲染视图 [英] How to render a View using AJAX in Spring MVC

查看:29
本文介绍了如何在 Spring MVC 中使用 AJAX 渲染视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring MVC,我需要对服务器进行异步调用并仅刷新页面的一部分.

I'm using Spring MVC and I need to make an asynchronous call to the server and refresh only a piece of the page.

我实际拥有的是一个返回字符串的控制器.我使用 JQuery (.post()) 函数调用控制器.

What I actually have is a Controller that returns a String. I call the Controller using JQuery (.post()) function.

我的解决方案的问题是我无法像使用 ModelAndView 作为返回类型时那样呈现 JSP.

The problem with my solution is that I'm not able to render a JSP like I do when I use ModelAndView as return type.

有没有办法返回已经渲染的视图?

Is there any way to return a View already rendered?

提前致谢.

纽基诺

推荐答案

你可以把这个页面放到一个单独的 JSP 中,并从你的方法中返回一个指向它的 ModelAndView.从这一点来看,AJAX 调用和非 AJAX 调用之间没有区别.

You can put this piece of page into a separate JSP and return a ModelAndView pointing to it from your method. There are no difference between AJAX and non-AJAX calls from that point.

这篇关于如何在 Spring MVC 中使用 AJAX 渲染视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆