469,898 Members | 1,710 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

How to write to a .txt file with Ajax Request?

hi every body

i want to upload file using Ajax ,i have try to use this code bellow ,but it's not work (i can't write helloworld in text1.txt).Du you no what is a problem ??me i configure anithing before it works ??PLEASE help me with some code .


Code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>javascript-only file writing</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript" src="bajax.js"></script>
  7.  
  8. <script type='text/javascript'>
  9. var fileName= "text1.txt";
  10. var data= "hello world";
  11.  
  12. function IO(U, V) { // A tiny ajax library. by DanDavis
  13. var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  14. X.open(V ? 'PUT' : 'GET', U, !1);
  15. X.setRequestHeader('Content-Type', 'text/html')
  16. X.send(V ? V : '');
  17. //return alert("resp: "+X.responseText);
  18. return X.responseText;
  19. }
  20.  
  21. // +++++++ customize code below ++++++++
  22.  
  23. function test(){
  24. alert("Data ist : "+data);
  25. IO( fileName, data ); //save it
  26. alert(" Data geschrieben in :" + fileName);
  27. //alert(IO( fileName )); //check the file
  28.  
  29. }
  30. </script>
  31. </head>
  32.  
  33. <body onload = "test()" >
  34.  
  35. </body>
  36. </html>
thank u in advance
Jan 31 '11 #1

✓ answered by Dormilich

the PUT method is usually deactivated on public servers (at least on all hosts I have come across), otherwise everyone could write to it. (I think PUT is disabled by default)

3 6504
Dormilich
8,652 Expert Mod 8TB
the PUT method is usually deactivated on public servers (at least on all hosts I have come across), otherwise everyone could write to it. (I think PUT is disabled by default)
Jan 31 '11 #2
Thank u for your Answer Dormilich,do u have any example how i can do that ? i have try to read a textfile but ,i can't write to it .Please when u any code or Idea how i can do that ,tel me please.

Thank u in Advance

Denis
Jan 31 '11 #3
Dormilich
8,652 Expert Mod 8TB
http://www.apacheweek.com/features/put
Feb 1 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by arunprabu | last post: by
3 posts views Thread by Simon | last post: by
1 post views Thread by nikki.farrah | last post: by
7 posts views Thread by Sebarry | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.