Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function send_request(r_method, r_path, r_args, r_handler)
- {
- var Request = false;
- if(window.XMLHttpRequest)
- {
- Request=new XMLHttpRequest();
- }
- else if (window.ActiveXObject)
- {
- try
- {
- Request = new ActiveXObject("Microsoft.XMLHTTP")
- };
- catch(CatchException)
- {
- Request=new ActiveXObject("Msxml2.XMLHTTP");
- }
- }
- if(!Request)
- {
- return;
- }
- Request.onreadystatechange=function()
- {
- if(Request.readyState==4)
- if(Request.status==200)
- r_handler(Request.responseText);
- if(r_method.toLowerCase() =="get"&&r_args.length>0)
- r_path+="?"+r_args;
- Request.open(r_method,r_path,true);
- if(r_method.toLowerCase()=="post")
- {
- Request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
- Request.send(r_args)
- }
- else
- {
- Request.send(null)
- }
- }
- }
- send_request("Тип запроса. get либо post","Путь/к/файлу.php","Аргументы. Например: topic=46764&page=4",function(response){
- //Код, который будет исполняться при успешном окончании запроса
- //response - переменная, содержащая ответ
- })
- <?PHP
- echo "Тестовая переменная: ".$_GET['testvar'];
- ?>
Add Comment
Please, Sign In to add comment