我是Spring框架的新手,我有一个问题。 我有一个页面A.jsp,该页面中我有一个链接到页面B.jspSpring dojo请求问题
<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)工作。 任何帮助都是值得欢迎的。 谢谢!
我不明白你的最后一句话,其中包含的问题和它应该是什么,所以很难给出答案。你能提供更多的信息吗? – g00glen00b
我的意思是在控制台中的错误消息说,没有找到requestPage.jsp页面。我想在同一页面中检索响应。 – tinti