Guest User

Untitled

a guest
Dec 11th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. function send_request(r_method, r_path, r_args, r_handler)
  2. {
  3. var Request = false;
  4. if(window.XMLHttpRequest)
  5. {
  6. Request=new XMLHttpRequest();
  7. }
  8. else if (window.ActiveXObject)
  9. {
  10. try
  11. {
  12. Request = new ActiveXObject("Microsoft.XMLHTTP")
  13. };
  14. catch(CatchException)
  15. {
  16. Request=new ActiveXObject("Msxml2.XMLHTTP");
  17. }
  18. }
  19. if(!Request)
  20. {
  21. return;
  22. }
  23. Request.onreadystatechange=function()
  24. {
  25. if(Request.readyState==4)
  26. if(Request.status==200)
  27. r_handler(Request.responseText);
  28. if(r_method.toLowerCase() =="get"&&r_args.length>0)
  29. r_path+="?"+r_args;
  30. Request.open(r_method,r_path,true);
  31. if(r_method.toLowerCase()=="post")
  32. {
  33. Request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
  34. Request.send(r_args)
  35. }
  36. else
  37. {
  38. Request.send(null)
  39. }
  40. }
  41. }
  42.  
  43. send_request("Тип запроса. get либо post","Путь/к/файлу.php","Аргументы. Например: topic=46764&page=4",function(response){
  44. //Код, который будет исполняться при успешном окончании запроса
  45. //response - переменная, содержащая ответ
  46. })
  47.  
  48. <?PHP
  49. echo "Тестовая переменная: ".$_GET['testvar'];
  50. ?>
Add Comment
Please, Sign In to add comment