Hi,
I just need simple example of using AJAX with Java in web developing. Lets say we have just simple page
We have of course class in a package:Code:<html> <header> \\ stuff like title, meta, etc. </header> <body> <div onclick="doAjax();" > whatever </div> </body> </html>
I think that this class is just OK. And we of course need to have some javascript:Code:package app.rpc; public class myClass extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String something = request.getParameter("something"); response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write("It works! " + something); } }
Thanks in advance,Code:// yea I know that this will not work with ie6 but leave it function initRequest() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if (window.ActiveXObject) { isIE = true; return new ActiveXObject("Microsoft.XMLHTTP"); } return false; } // I think here problem comes function doAjax() { var url = "myTomcatContext/app.rpc.myClass?something=Hello-World"; // I'm not sure if path is correct var req = initRequest(); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200) { parseMessages(req.responseXML); // and not sure of this } else if (req.status == 204){ clearTable(); } } } req.open("GET", url, true); // I would like also POST version - if someone can help I'll be thankful req.send(null); alert(response+ '!'); \\ I want all data ( "It works! Hello-world!" should be here) }
Marcin
you can use responseText property instead, i think its working fine all you need to do is to see the results:
if you are using firefox get firebug plugin it will help you see the requests and responses by your page
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
www.amrosama.com | the unholy methods of javascriptCode:eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks