如何从春到控制器的AJAX调用呈现新的JSP页面 [英] How to render new jsp page from ajax call to Spring Controller
问题描述
我使用的春天,我有
锚标签列表如下图所示,我需要做的呼叫后,所以我使用AJAX查询。
Anchor tags list like below and i need to make post call so i used ajax query.
<td><a href="#" onclick='doAjax(${taskDetail.taskId})'> ${taskDetail.taskTitle}</a></td>
在我同一个JSP我有Ajax调用如下
in my same jsp i have ajax call as below
function doAjax(x) {
alert(x);
$.ajax({
type: "POST",
url: "getTaskDetail",
data: { taskId: x }
}
})
}
现在我控制器
@RequestMapping(value = "/getTaskDetail", method = RequestMethod.POST)
public String getTaskDetail(@RequestParam String taskId, Model model) {
System.out.println("i am herer......");
try {
TaskDet taskDet = getTaskinformation(Integer.parseInt(taskId));
model.addAttribute("taskDet", taskDet);
return "showtaskpage";
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
现在我的showtaskpage本身的.jsp页。
now my "showtaskpage" itself is .jsp page.
现在的问题是,一切正常般的魅力,但是,当它返回showtaskpage,它是没有得到遭遇到新的jsp页面,我仍然在previous页面,当我点击这个锚链接,它会到控制器,并得到回应,但我会得到的.jsp整页的数据格式,我们可以使用萤火虫看到它。
now the problem is that , everything works like charm , but when it returns showtaskpage, it is not getting rentered in new jsp page , I am still in the previous page and when i click this anchor link , it goes to the controller and get response but i will get .jsp full page as data format , we can see it using firebug.
我想显示为的http://本地主机:8080 / mydummy / showtaskpage
在此先感谢。
推荐答案
我已经修改如下
$.ajax({
type: "POST",
url: "getTaskDetail",
data: { taskId: x },
success : function(data) {
alert('success');
document.open();
document.write(data);
document.close();
}
})
我现在发生的事情是,将呈现新的JSP页面的工作。
now i what happens is it will render as new JSP page working .
这篇关于如何从春到控制器的AJAX调用呈现新的JSP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!