ajax.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * check get or post
  4. *
  5. */
  6. /*加上这句使得当php配置显示Notice提示信息时也不会报错*/
  7. error_reporting(E_ERROR | E_WARNING);
  8. if ($_SERVER['REQUEST_METHOD'] == 'POST') { // POST请求
  9. $img1 = $_POST['img1'];
  10. $img2 = $_POST['img2'];
  11. $content = $_POST['content'];
  12. $str = '';
  13. if ($img1 && $img2) {
  14. $str = "img1='" . $img1 . "'&img2='" . $img2 . "'";
  15. }
  16. if ($content) {
  17. if ($img1) {
  18. $str .= '&';
  19. }
  20. $str .= $content;
  21. }
  22. echo $str;
  23. } else if (isset($_GET['callback'])) { // jsonp做的GET请求
  24. $callback = $_GET['callback'];
  25. echo $callback . '(' . json_encode($_GET) . ')';
  26. } else { // 普通GET请求
  27. $get1 = $_GET['get1'];
  28. $get2 = $_GET['get2'];
  29. $img1 = $_GET['img1'];
  30. $img2 = $_GET['img2'];
  31. $content = $_GET['content'];
  32. $str = '';
  33. if ($get1 && $get2) {
  34. $str .= "get1='" . $get1 . "'&get2='" . $get2 . "'";
  35. }
  36. if ($img1 && $img2) {
  37. if ($get1) {
  38. $str .= '&';
  39. }
  40. $str .= "img1='" . $img1 . "'&img2='" . $img2 . "'";
  41. }
  42. if ($content) {
  43. if ($img1 || $get1) {
  44. $str .= '&';
  45. }
  46. $str .= $content;
  47. }
  48. echo $str;
  49. }
  50. ?>