Posted By

krisdb on 04/25/07


Tagged

javascript


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

iNiels
vali29
korzhik
umang_nine
guo3823538


Ajax


 / Published in: JavaScript
 

  1. var req;
  2.  
  3. function backupStory() {
  4. req = false;
  5.  
  6. var title = document.FORM.FIELD.value;
  7. var content = document.FORM.FIELD.value;
  8.  
  9. // branch for native XMLHttpRequest object
  10. if(window.XMLHttpRequest) {
  11. try {
  12. req = new XMLHttpRequest();
  13. } catch(e) {
  14. req = false;
  15. }
  16. // branch for IE/Windows ActiveX version
  17. } else if(window.ActiveXObject) {
  18. try {
  19. req = new ActiveXObject("Msxml2.XMLHTTP");
  20. } catch(e) {
  21. try {
  22. req = new ActiveXObject("Microsoft.XMLHTTP");
  23. } catch(e) {
  24. req = false;
  25. }
  26. }
  27. }
  28.  
  29. // POST
  30. if(req) {
  31.  
  32. var sURL = 'page.asp';
  33.  
  34. var params = 'title='+escape(title)+'&content='+escape(content);
  35.  
  36. req.open('POST', sURL, true);
  37. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  38. req.setRequestHeader("Content-length", params.length);
  39. req.setRequestHeader("Connection", "close");
  40.  
  41. req.onreadystatechange = function() {
  42.  
  43. if(req.readyState == 4 && req.status == 200) {
  44. document.getElementById('').innerHTML = req.responseText;
  45. }
  46. }
  47. req.send(params);
  48. }
  49. }
  50.  
  51. //GET
  52. if(req) {
  53. var sURL = 'page.asp?title='+escape(title)+'&content='+escape(content);
  54. req.open("GET", sURL, true);
  55.  
  56. req.onreadystatechange = function(){
  57.  
  58. if(req.readyState == 4 && req.status == 200)
  59. document.getElementById('').innerHTML = req.responseText;
  60.  
  61. }
  62. req.send("");
  63. }
  64. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: krisdb on July 11, 2007

You need to login to post a comment.