Advertisement
piffy

AJAX con POST (parte JS - ajax2.js)

Aug 13th, 2015
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PostData() {
  2.    // 1. Istanziazione della richiesta (semplificata)
  3.     var xhr;
  4.     xhr = new XMLHttpRequest();
  5.    // 2. Gestire la risposta del server
  6.    xhr.onreadystatechange = function () {
  7.         if (xhr.readyState === 4) {
  8.             if (xhr.status == 200 && xhr.status < 300) {
  9.                 document.getElementById('div1').innerHTML = xhr.responseText;
  10.             }
  11.         }
  12.     }
  13.     // 3. Specificare metodo, URL e avviare le operazioni
  14.     var userid = document.getElementById("userid").value;  
  15.     xhr.open('POST', 'controllo.php');
  16.     xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  17.     xhr.send("userid=" + userid);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement