-5

Below is the required task :

  1. Make an Ajax post to server (eg. "http://192.168.1.107:80" )
  2. On response, make a get request to server asking for values
  3. Update input box with returned values.

Note : Page should not refresh during the process

Nikhil Maheshwari
  • 2,198
  • 18
  • 25
  • read about AJAX (http://stackoverflow.com/tags/ajax/info) – Berriel Aug 21 '15 at 20:43
  • yes its possible - you will probably need to use callbacks/promises since ajax requests are asynchronous (so the get doesn't run until the post is finished) – Maverick976 Aug 21 '15 at 20:58
  • 1
    possible duplicate of [How to return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) – Didier Aupest Aug 21 '15 at 20:58
  • Hello and thank you very much for your answers!!!.Is it possible to provide me some sort of code because i am completely rookie to js and ajax? – Panagiotis Aug 22 '15 at 07:01

1 Answers1

0

Below CodePen can help you get started: Your query should also be resolved with this.

 <html>
 <input id='inp1' type='text'/>
 </html>

 <script>
 var xhrObject = new XMLHttpRequest();

 xhrObject.onreadystatechange = function() {
  if (xhrObject.readyState === 4) {
   if (xhrObject.status === 200 || xhrObject.status === 304) { 
     console.log(xhrObject.responseText);
     var inp = document.getElementById('inp1');
     inp.value = xhrObject.responseText;
    }
  }
};

xhrObject.open(
  "GET", 
  "http://codepen.io/chriscoyier/pen/difoC.html", 
  true
);
xhrObject.send();
</script>

CodePen : http://codepen.io/anon/pen/LVKMOX

Nikhil Maheshwari
  • 2,198
  • 18
  • 25
  • Hello my friend and thank you for tidying up my request. The code you posted doesn't do what i try to do.... i am new here this is my first post and i don't know much yet Also i would like to tell that i am completely rookie to javascript....regards – Panagiotis Aug 21 '15 at 21:39