views:

18

answers:

0

Hi,

I have a REST web service located at http://localhost/doSomething accepting HTTP GET e.g. http://localhost/doSomething/1. It @Consumes nothing and @Produces application/xml or application/json.

I'd like to be able to call this web service from a simple HTML form/JavaScript but I while I can get the web service to invoke I cannot get a response to process. Here is my JavaScript function:

function doREST(){
var field= document.getElementById('field').value;
var ws = 'http://localhost:8080/myService/myOperation/';
var url = ws + field;
alert(url);
var xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
alert('Whoops! Your browser does not support XMLHttpRequest!');
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert("Success");
}
else {
alert("Failure");
}
};
xmlhttp.open('GET', url, true);
xmlhttp.send(null);
}