nap4110
Mar 28th, 2007, 04:52 PM
Not 100% if this is a Spring issue or an AJAX issue, but wanted to see what other people have tried. What I want to do is fairly simple: Grab data from the "server" and display it. Here's the code that sends the request to the server:
function changeStates(Id ) {
var url = "trackerMap.htm?id=" + encodeURIComponent(Id);
if (typeof XMLHttpRequest != "undefined") {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", url, true);
req.onreadystatechange = parseMessage;
alert("about to send");
req.send(null);
}
My servlet maping works and the proper Controller( which extends MultiActionController) does get called. Here is the code:
public ModelAndView getTrackerMap(HttpServletRequest request, HttpServletResponse response)
throws Exception {
//create the xml
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<message>valid</message>");
return null;///tried returning new ModelAndView as wel
}
And the callback does happend in the javascript. The only problem is that there doesn't seem to be any data, or I am not retrievin the data properly!
function parseMessage() {
alert("parseMEssage");
var message = req.responseXML.getElementsByTagName("message")[0];
alert("Here we are"+req.responseXML.getElementsByTagName("message")[0]);
alert(message.childNodes[0].nodeValue);
}
Any ideas on what I am doing wrong or further steps I can take to debug this?
function changeStates(Id ) {
var url = "trackerMap.htm?id=" + encodeURIComponent(Id);
if (typeof XMLHttpRequest != "undefined") {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", url, true);
req.onreadystatechange = parseMessage;
alert("about to send");
req.send(null);
}
My servlet maping works and the proper Controller( which extends MultiActionController) does get called. Here is the code:
public ModelAndView getTrackerMap(HttpServletRequest request, HttpServletResponse response)
throws Exception {
//create the xml
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<message>valid</message>");
return null;///tried returning new ModelAndView as wel
}
And the callback does happend in the javascript. The only problem is that there doesn't seem to be any data, or I am not retrievin the data properly!
function parseMessage() {
alert("parseMEssage");
var message = req.responseXML.getElementsByTagName("message")[0];
alert("Here we are"+req.responseXML.getElementsByTagName("message")[0]);
alert(message.childNodes[0].nodeValue);
}
Any ideas on what I am doing wrong or further steps I can take to debug this?