readResponse.js 986B

1234567891011121314151617181920212223242526272829303132
  1. //#########################################################
  2. // Part of project php-IRC-js
  3. //
  4. // xhr_write.php - Read responses
  5. //
  6. // Author: Mario Chorvath - Bedna
  7. // Start 2016
  8. //
  9. // Licence GNU General Public License
  10. // Version 2
  11. // http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
  12. //#########################################################
  13. // Write data on server
  14. function readResponse () {
  15. // Create new XHR
  16. var xhr = new XMLHttpRequest(); // New XHR2
  17. // If "read_response.php" send data back
  18. xhr.onreadystatechange = function() {
  19. if (xhr.readyState == 4 && xhr.status == 200) {
  20. document.getElementById("status").innerHTML = "&gt;&gt;&gt;" + xhr.responseText + "</b><br>";
  21. }
  22. };
  23. // Send data to server
  24. xhr.open ("GET", "read_response.php", true); // Sync open file
  25. xhr.responseType = 'text';
  26. xhr.setRequestHeader ("Content-Type", "application/octet-stream");
  27. xhr.setRequestHeader ("X-TEXT", message); // Custom header - file name
  28. xhr.send (); // Send
  29. };