我对 Spring 框架很陌生,但我遇到了问题。我有一个页面 A.jsp,在这个页面中我有一个指向页面 B.jsp 的链接
<c:url value="${pageContext.request.contextPath}" var="contextPath" />
Click <a href="${contextPath}/pageB">here</a>
在控制器中
@RequestMapping("pageB")
public String pageBlink(SitePreference sitePreference, Device device, Model model) {
return "pageB";
}
现在在 B.jsp 页上,我想调用 Ajax 调用。
I have a link <a href="javascript:myFunction();">Send request</a>
function myFunction(){
dojo.xhrGet({
// The URL of the request
url: "requestPage",
method: "POST",
handleAs: "json",
// The success callback with result from server
load: function(jsonData) {
var content = "";
dojo.forEach(jsonData.newsItems,function(locationPoint) {
// Build data from the JSON
content += "<p>" + locationPoint.name + "</p>";
content += "<p>" + locationPoint.latitude + "</p>";
content += "<p>" + locationPoint.longitude + "</p>";
content += "<p>" + locationPoint.number + "</p>";
});
},
// The error handler
error: function() {
// Do nothing -- keep old content there
},
// generate an extra GET variable to prevent browsers from caching
preventCache: true
});
}
并添加到控制器
@RequestMapping(value="requestPage", method = RequestMethod.GET)
public MyObj returnEVSELocations(){
logger.log(Level.INFO, "return evse locations --------------");
MyObj myObj = new MyObj();
// add some stuff into the obj
return myObj;
}
但是这个请求是 requestPage.jps ......我只想在我的页面(B.jsp)中工作。任何帮助都非常受欢迎。谢谢!