Simple JSF AJAX requests can be achieved within JSF (JSP) as follows:
- JavaScript - make the request to get data from the AJAX Servlet
- Ajax Servlet - process the request and send the XML/JSON/plain text response
- JavaScript - process the response and use the data on the page
For example:
<script type="text/javascript" language="Javascript">
// get the ajax request object (from Ajax.js)
var http = getAjaxRequestObject();
// connect to the server (URL to the AjaxServlet)
http.open('GET', '/myjsfapp/faces/AjaxSevlet?param1="foo"¶m2="bar"');
// assign a handler for the response
http.onreadystatechange = processResponse;
// send the request to the server
http.send(null);
function processResponse() {
// if the response has been received from the server
if (http.readyState == 4) {
// read the response from the server
var response = http.responseText;
// process the response
// e.g. parse the XML, JSON etc.
...
}
}
</script>
No comments:
Post a Comment