I am trying to learn Ajax, but I have a hard time getting it.
I have a Java servlet that will give me data from DB, and I am trying to create a simple web page which constantly asks for an update every 5 seconds, and then reload the page Displays without doing I also do not want to do this on state preparedness, but only once every 5 seconds.
// xmlHttp = xmlHttpRequest Object Function Process () {try (if xmlHttp .readyState == 4 || xmlHttp.readyState == 0} {xmlHttp.open ("GET", 'LocalHost : 8080 ', is true); // handleServerResponse (); // Get data from the server, not on the state change, but always? Set intern ('process ()', 5000); } Other {setTimeout ('process ()', 5000); }} Hold (e) {warning ('main process did not work'); Warning (e.toString ()); }}
I am uncertain how can I complete it. what is missing?
The following steps include obtaining data from the server
When is ready 4 and the situation is 200. Your request on the server is successful and you receive a response in request.responseHTML
or request.responseXML
. Which you use for processing it
windown.onload = initialize; Function initialize () {setInterval (process, 5000); } Request request; Function Process () {Request = getAJAXREQUETOBJECT; Request.open ("receive", "url", true); request. Request.send (true); } Function requestresponse () {if (request.readystate == 4 & request.status == 200} {// request.response manipulate with HTML or request.responseXML}}
< / Li>
No comments:
Post a Comment