当前位置: 代码迷 >> Ajax >> 简略的ajax记事本
  详细解决方案

简略的ajax记事本

热度:438   发布时间:2013-10-28 11:21:45.0
简单的ajax记事本

记事本,同时只能记录一个文件,存为了txt文本文档

注意本例用了一些css和js文件,请在演示页面另存为后查看

演示

?

PHP Code
  1. <?php??
  2. ??
  3. $note_name?=?'note.txt';??
  4. $uniqueNotePerIP?=?true;??
  5. ??
  6. if($uniqueNotePerIP){??
  7. ??????
  8. ????//?Use?the?user's?IP?as?the?name?of?the?note.??
  9. ????//?This?is?useful?when?you?have?many?people??
  10. ????//?using?the?app?simultaneously.??
  11. ??????
  12. ????if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){?
  13. ????????$note_name?=?'notes/'.md5($_SERVER['HTTP_X_FORWARDED_FOR']).'.txt';?
  14. ????}?
  15. ????else{?
  16. ????????$note_name?=?'notes/'.md5($_SERVER['REMOTE_ADDR']).'.txt';?
  17. ????}?
  18. }?
  19. ?
  20. ?
  21. if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])){?
  22. ????//?This?is?an?AJAX?request?
  23. ?????
  24. ????if(isset($_POST['note'])){?
  25. ????????//?Write?the?file?to?disk?
  26. ????????file_put_contents($note_name,?$_POST['note']);?
  27. ????????echo?'{"saved":1}';?
  28. ????}?
  29. ?????
  30. ????exit;?
  31. }?
  32. ?
  33. $note_content?=?'??
  34. ??
  35. ????????????????Write?your?note?here.??
  36. ??
  37. ?????????????It?will?be?saved?with?AJAX.';??
  38. ??
  39. if(?file_exists($note_name)?){??
  40. ????$note_content?=?htmlspecialchars(?file_get_contents($note_name)?);??
  41. }??
  42. ??
  43. ?>??

?

XML/HTML Code
  1. <div?id="pad">??
  2. ????????????<h2>Note</h2>??
  3. ????????????<textarea?id="note"><?php?echo?$note_content??></textarea>??
  4. ????????</div>??

?


原文地址:http://www.freejs.net/article_jquerywenzi_68.html

  相关解决方案