there is a page:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="Style/Global.css"> <script src="JS/Librarie.js"></script> </head> <body onLoad="Global();"> <header id='Header'> </header> <aside id='AsideLeft'> </aside> <div id='Content'> <div id='Conteiner'> <div style='width: 100%; height: 100%; ' id='loader'> </div> </div> </div> </body> </html> 

Browsing machine:

 <?php session_start(); include ("bd.php"); if (isset($_COOKIE['auto']) and isset($_COOKIE['email']) and isset($_COOKIE['password'])) { if ($_COOKIE['auto'] == 'yes') { $_SESSION['password']=strrev(md5($_COOKIE['password']))."b3p6f"; $_SESSION['email']=$_COOKIE['email']; $_SESSION['id']=$_COOKIE['id']; if (!empty($_SESSION['email']) and !empty($_SESSION['password'])) { $email = $_SESSION['email']; $password = $_SESSION['password']; $result = mysql_query("SELECT * FROM users WHERE email='$email' AND password='$password' AND activation='1'",$db); $myrow = mysql_fetch_array($result); $email = $myrow['email']; } } } if (!empty $email) { $menu = " <div class='Menu3'> Новости </div> <div class='Menu3'> Друзья </div> <div class='Menu3'> Диологи </div> <div class='Menu3'> Фотографии </div> <div class='Menu3'> Настройки </div> " }else{ $menu = " <div class='Menu3'> Войти </div> <div class='Menu3'> Регистрация </div> " } ?> 

It is necessary without reloading the page, contact the processing provider and push the $ menu variable into <aside id = 'AsideLeft'>


meanwhile something happens

  function getXmlHttp(){ var xmlhttp; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } return xmlhttp; } function Global() { var req = getXmlHttp(); var statusElem = document.getElementById('AsideLeft'); req.onreadystatechange = function() { if (req.readyState == 4) { // если запрос закончил выполняться statusElem.innerHTML = req.statusText // показать статус (Not Found, ОК..) if(req.status == 200) { statusElem.innerHTML = req.responseText; // если статус 200 (ОК) - выдать ответ пользователю } // тут можно добавить else с обработкой ошибок запроса } }'GET', 'Formers.php', true); req.send(null); // отослать запрос statusElem.innerHTML = 'Ожидаю ответа сервера...' } 

But neither goes: (((

  • Discover the debugger (it’s built-in in chrome, and FireBug needs to be installed in FF) see what goes in Ajax request and what comes and everything will be clear at once - Alex Kapustin

1 answer 1

In PHP code, I don’t see that the result of assigning $menu is somehow used. By itself, it does not appear. The rest of the code looks workable, so I think the problem is this.

But if there are no contraindications or goals to understand the details of the engine compartment - do not torture yourself with the invention of bicycles, take the same jQuery . All footcloth code will be reduced to:

 jQuery(function($) { var target = $("#AsideLeft"); target.text("Ожидаю ответа сервера…"); $.get("Formers.php", function(data) { target.html(data); }); }); 
  • And if there are several variables and they need to be distributed in different places? - Kirpich643
  • Or cycling: // php: echo json_encode (array ("foo" => "...", "bar" => "...")); $ .getJSON ("foo.php", function (data) {$ ("# foo"). html (; $ ("# bar"). html (;}); Or take a ready-made solution for client-side templates. jQuery templates, Handlebars , thousands of them. Or not templating at all, but data binding, such as Knockout.js or, there, Backbone.js + Rivest.js. - drdaeman 4:21