есть у меня два файла, скрин в аттаче.
test.php
Код |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /><?php ?><html xmlns="http://www.w3.org/1999/xhtml" /><?php ?><head><?php ?><meta http-equiv="content-language" content="ru" /><?php ?><meta http-equiv="content-type" content="text/html; charset=windows-1251" /> <html> <head> <script type="text/javascript" language="javascript"> var req = Create(); function ge(id) { return document.getElementById(id); } function Create(){ if(navigator.appName == "Microsoft Internet Explorer"){ req = new ActiveXObject("Microsoft.XMLHTTP"); }else{ req = new XMLHttpRequest(); } return req; } function Request(query) { req.open('post', 'ajax.php' , true ); req.onreadystatechange = Refresh; req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); req.send(query); } function Refresh() { if( req.readyState == 4 ) ge('ajax').innerHTML = req.responseText; else ge('ajax').innerHTML = ''; } function Pusk() { var query; query ='txt='+encodeURIComponent(ge('myid').value); Request(query); } </script> <style> .gt { padding: 0px 0px 3px 0px;} .gm { background-color: #FFFFFF; text-align: justify; border-top: 3px solid #EEEEEE; border-right: 3px solid #999999; border-bottom: 3px solid #999999; border-left: 3px solid #EEEEEE; padding: 7px 20px 7px 20px; height: 160px; } </style> </head> <body bgcolor="#eeeeee"> <table width="96%" height="500" align="center" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center"> <div class="gm"><div class="gt"> <div id="ajax"></div> </div></div> <input type='text' id='myid' size="150"> <input type="button" value="Послать" onClick="Pusk()"> </td> </tr> </table> <div align="center">бла бла бла необновляющийся контент</div> </body> </html> |
PHP |
$txt = isset($_POST['txt'])?$_POST['txt']:NULL; |
Код |
function doLoad(force) { var query = document.getElementById('query').value; var req = new Subsys_JsHttpRequest_Js(); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.responseJS) { document.getElementById('result').innerHTML = req.responseJS.m; }}} req.caching = false; req.open('POST','otvet.php', true); req.send({ q: query, test:303 }); doLoadUp(); } var timeout = null; function doLoadUp() { if (timeout) clearTimeout(timeout); timeout = setTimeout(doLoad, 1000); } |
Цитата |
Сессия будет работать в файле ajax.php? |
Цитата (Gram @ 16.09.2009 - 15:37) |
А вообще нормально, то что кусочек сайта будет обновляться каждую секунду? |
Цитата |
файл test.php по нажатию кнопки передает данные в ajax.php, |
Цитата |
А вообще нормально, то что кусочек сайта будет обновляться каждую секунду? |