Ajax: Return java agent value to web page

I have a web page with a button. When the button is pressed, it runs some code and calls a java agent. The java agent will do some processing and populate a string variable.

How can i return the value computed by this java agent (e.g. myString = ‘This is my result’) back to the web page, of course, without refreshing the web page.

Please advice, thanks.

Subject: Ajax: Return java agent value to web page

function getAJAXContent(url) { var ajaxObj;

var result;



try {ajaxObj = new XMLHttpRequest();} catch(e) {ajaxObj = new ActiveXObject("Msxml2.XMLHTTP");}



ajaxObj.onreadystatechange = function() { 

	if(ajaxObj.readyState  == 4) {

		if(ajaxObj.status  == 200) {

			result = ajaxObj.responseText;

		} else  {

			result = "ERROR";

		}

	}

};

ajaxObj.open("GET", url+"?dummy="+new Date().getTime(),true); 

ajaxObj.send(null);



return result;

}

…not sure if that was what you were looking for?

Notes:

  1. try…catch line is so it works on IE and Firefox.

  2. ?dummy="+new Date().getTime() is to avoid caching in some circumstances. Note you should really encode this but it normally works without doing so.