私は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)で作業したいだけです。どんな助けでも大歓迎です。ありがとう!