ziedinjsh Posted November 29, 2012 Report Share Posted November 29, 2012 Sveiki! veicu datu post, ja viss ir ok tad izveido sessiju un updato div kurā ir forma. Formai pēc pieprasījuma ir jānomainas uz sessijas nosaukumu, bet tā vietā parādās tukšums. Sanāk tā, ka pārlūks neatpazīst sesiju bez lapas pārlādēšanas? Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 29, 2012 Author Report Share Posted November 29, 2012 <html> <head> <script type="text/javascript" src="jquery-1.8.3.min.js"></script> <script type="text/javascript"> jQuery(function(){ jQuery('#form').submit(function(){ jQuery.ajax({ type: 'POST', url: jQuery('#form').attr('action'), data: jQuery('#form').serialize(), success: function(data){ if(data == 'success'){ jQuery('#user').load(location.href+' #user>*'); }else{ jQuery('#info').html(data); } } }); return false; }); }); </script> </head> <body> <div id="user"> <div id="info"></div> <?php session_start(); if(isset($_SESSION['user'])){ echo $_SESSION['user']; }else{ echo ' <form method="post" action="session.php" id="form"> <input type="text" name="user" /> <input type="submit" name="do" value="ok" /> </form> '; } ?> </div> </body> </html> <?php $user = mysql_real_escape_string($_POST['user']); if(empty($user)){ echo 'psc'; }else{ echo 'success'; session_start(); $_SESSION['user'] = $user; } ?> Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 29, 2012 Author Report Share Posted November 29, 2012 Viss kas Tev sakāms? Quote Link to comment Share on other sites More sharing options...
briedis Posted November 29, 2012 Report Share Posted November 29, 2012 Ieslēdz kļūdu ziņošanu un redzēsi to leģendāro kļūdu - headers already sent... Quote Link to comment Share on other sites More sharing options...
webi Posted November 30, 2012 Report Share Posted November 30, 2012 session_start() raksti pašā dokumenta augšā pirms kāds simbols ir izvadīts. no php.net: This function sends out several HTTP headers depending on the configuration. See session_cache_limiter() to customize these headers. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 30, 2012 Author Report Share Posted November 30, 2012 Tas neko nemaina. Nerādās tāpat, bet ir tāda interesanta lieta, lapānerādās sesijas nosaukums, bet paskatoties page source tur viņš ir redzams! Quote Link to comment Share on other sites More sharing options...
Kemito Posted November 30, 2012 Report Share Posted November 30, 2012 Sāc vien ar to, ka palasi mazliet par ( MVC ) kā tādu. Otrā lieta, sāc šeit ar to, ka php kodu, kas ir kopā ar HTML liec augšā, vēl bonusā session_start(); liec pašā augšā. ini_set('display_errors', 'On'); error_reporting(E_ALL); Tas jau tev sāks dot pavedienus uz - kapēc neJiet. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 30, 2012 Author Report Share Posted November 30, 2012 man jau ir <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); session_start(); ?> <html> <head> <script type="text/javascript" src="jquery-1.8.3.min.js"></script> <script type="text/javascript"> jQuery(function(){ jQuery('#form').submit(function(event){ event.preventDefault(); jQuery.ajax({ type: 'post', url: jQuery('#form').attr('action'), data: jQuery('#form').serialize(), success: function(data){ if(data == 'success'){ jQuery('#user').load(location.href+' #user>*'); }else{ jQuery('#info').html(data); } } }); return false; }); }); </script> </head> <body> <div id="user"> <div id="info"></div> <?php if(isset($_SESSION['user'])){ echo $_SESSION['user'].' | <a href="off.php">iziet</a>'; }else{ ?> <form method="post" action="session.php" id="form"> <input type="text" name="user" /> <input type="submit" name="do" value="ok" /> </form> <?php } ?> </div> </body> </html> bet rezūltāts tāds pats! Quote Link to comment Share on other sites More sharing options...
indoom Posted November 30, 2012 Report Share Posted November 30, 2012 Un tajā session.php session_start() pārliki uz sākumu? Quote Link to comment Share on other sites More sharing options...
ezis Posted November 30, 2012 Report Share Posted November 30, 2012 echo 'success';session_start(); Tu izvadi HTML pirms header`u izvades. Nočeko, kādu saturu Tev atgriež session.php Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 30, 2012 Author Report Share Posted November 30, 2012 nu ja es formu postoju bez jquery tad viss izvadās tā kā tam jābūt. Quote Link to comment Share on other sites More sharing options...
ezis Posted November 30, 2012 Report Share Posted November 30, 2012 <?php // pievieno šīs divas savā session.phpini_set('display_errors', 'On');error_reporting(E_ALL); Un Tev vajadzētu redzēt kļūmi iekš <div id="info"></div> Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 30, 2012 Author Report Share Posted November 30, 2012 nop, nekas neizvadās.. tukšs div un iekš source koda parādās vajadzīgais rezūltāts- sessijas nosaukums Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 30, 2012 Author Report Share Posted November 30, 2012 jā, bet, nu iekš div #user ir viena vai otra informācija. Ja ir sessija user tad ar echo $_SESSION['user']; bet ja nav sessija tad ir forma.. tiek it kā izvadīts echo, vienīgi ja domāji uzreiz tajā session.php failā to darīt? Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 30, 2012 Author Report Share Posted November 30, 2012 doma ir tāda, ka ir it kā portāls un vienā stūrī ir login forma.. ievada informāciju un uelogojas bez lapas pārlādes. login formu aizvieto ar bildi un izvēlni nelielu. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.