Invoke Java servlet with YUI
Aug31Difficulty: 




In one of my previous post I showed you how to invoke a Java servlet with Ajax/Javascript.
Now I will show you the same example with the use of Yahoo UI Library (YUI Library).
Make sure you implement the yahoo and connection libraries.
You can download these from the YUI developer network.
<script type="text/javascript" src="static/js/yui/yahoo-min.js"></script> <script type="text/javascript" src="static/js/yui/connection-min.js"></script>
The script:
<script type="text/javascript">
var request;
function doSomeRequest(servletName, servletArguments){
var arg = "myParam=" + getPopupContent(servletArguments).replace(/[\n\r\%]/g,''); //I replaced linebreaks and % which breaks requests.
YAHOO.util.Connect.asyncRequest('POST', servletName, callback, arg); //note the arg is only for POST methods
var callback =
{
success: function(o) {
//do something with the response
},
failure: function(o) {
//do something with the error
}
}
}
</script>
Download the files or see more examples on YUI Developer network.
Posted in YUI Library, javascript |ajax, / java, / java servlets, / Javascript Frameworks, / post data, / yui
» Post your comment, there are no comments yet. »
Comments
- Pulkit Singhal
- Neil
- mike nittmann
- geniutrixone
- Mika
- Romfrosk
- steve
- shahzad
- Maurice
- Lee
- Oskar Krawczyk