send.js 936B

1234567891011121314151617181920212223242526272829303132333435
  1. //#########################################################
  2. // Part of project php-IRC-js
  3. //
  4. // xhr_write.php - Read response
  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 send () {
  15. // New XHR2 request
  16. var xhr = new XMLHttpRequest(); // New XHR2
  17. message = encodeURIComponent (document.getElementById("message").value);
  18. console.log ('message :' + message);
  19. if (message) {
  20. // Send data to server
  21. xhr.open ("GET", "send.php", true); // Sync open file
  22. xhr.responseType = 'text';
  23. xhr.setRequestHeader ("Content-Type", "application/octet-stream");
  24. xhr.setRequestHeader ("X-TEXT", message); // Custom header - file name
  25. xhr.send (); // Send
  26. }
  27. // If mesage is empty
  28. else {
  29. alert ("Message is empty");
  30. }
  31. };