I can´t get the response from an object XMLHttpRequest as a result of a REST call. I know that results are inside the object cause the object size is bigger when I have results to return but I can´t access to them anyway. This is my javascript request to the server:
function getMarkersByCategory(category) {
var urlServer = 'http://localhost:8080/api/mapit/getcategory';
return loadContent(urlServer,category);
}
function loadContent(url, category) {
var mypostrequest = new ajaxRequest();
mypostrequest.onreadystatechange = function() {
if (mypostrequest.readyState == 4) {
if (mypostrequest.status == 200 || window.location.href.indexOf("http") == -1) {
return displayMarkers(mypostrequest);
}
else {
alert("An error has occured making the request");
}
}
}
var parameters = "?category=" + category ;
mypostrequest.open("GET", url + parameters , true);
mypostrequest.send(null);
}
function ajaxRequest() {
var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
if (window.ActiveXObject) { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
for (var i = 0; i < activexmodes.length; i++) {
try {
return new ActiveXObject(activexmodes[i]);
}
catch (e) {
//suppress error
}
}
}
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
return new XMLHttpRequest();
else
return false;
}
function displayMarkers(data) {
alert(data);
var jsonContent = data // I can´t find any property of the object with the response
}
And finally this is the response of my Java web service:
@GET
@Produces("text/plain")//I have tried with ("application/json") too
@Path("/getcategory")
public String getByCategory(@QueryParam("category") String category) {
List<MapItBean> list = mapItPointDao.getMapItPointsByCategory(category);
String result = MapItBeanHelper.jsonizeMapitList(list);
System.out.println(result);
return result;
}
I tried as well using jquery but I have the same problem, I can´t get any response. Thanks in advance.