Just started to learn ajax and completely confused (
She seems to have found a good example - http://uroki-javascript.ru/tryit.php?filename=tryajax_get_unique
Guys, tell me, please, because in addition to this code there must be some kind of code on the servlet?

 <![CDATA[ <!DOCTYPE html> <html> <head> <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// код для IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// код для IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","demo_get.php?t=" + Math.random(),true); xmlhttp.send(); } </script> </head> <body> <h2>AJAX</h2> <button type="button" onclick="loadXMLDoc()">Запросить дату</button> <p>Кликните кнопку несколько раз, чтобы увидеть, изменяется ли время или возвращается кэшированный файл (в этом случае время будет одно и то же).</p> <div id="myDiv"></div> </body> </html> ]]> 
  • In fact, this is the same request to the server, only "without reloading the page." - lampa
  • Can you explain how to handle? I'm just starting to deal with ajax. - AnnaReznicova
  • @AnnaReznicova well, do you have java on the server? - lampa
  • Yes, there is a servlet. The question is how to get a parameter from the doGet method (in a servlet) that we pass to - Math.random (). To then, for example, just bring it to the console. This is what I do not understand. - AnnaReznicova
  • And, so ajax is nothing to do with. In essence, a page is requested with the get parameter t. I, of course, do not use java, but Google hints at: public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {String time = req.getParameter ("t"); } - lampa

0