Ajax Call with Strut2
//----- Write in JavaScript---------------------
function findAppointment(strValue) {
if (typeof XMLHttpRequest != "undefined") {
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp == null) {
alert("Browser is campatible ...tht must IE");
}
var id = strValue.value;
var url = "getDetailsAjax"; // URL
url += "?id=" + id; // Parameters
xmlHttp.onreadystatechange = getDts; // get response method
xmlHttp.open("POST", url, true);
xmlHttp.send(null);
}
// here you will get the response of your ajax call
function getDts () {
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
var data = xmlHttp.responseText;
alert(data);
}
}
<!—Ajax Struts Configuration Call -->
<action name="*Ajax" class="com.ajax.DetailsAction" method="{1}">
<result type="stream">
<param name="inputName">inputeStream</param>
</result>
</action>
// Action method of DetailsAction
public String getDetailsAjax () throws Exception{
String ajaxString = new String()
try {
ajaxString += “sandeep”;
inputeStream = new StringBufferInputStream(ajaxString);
inputeStream.reset();
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
No comments:
Post a Comment