Jump to content
php.lv forumi
ziedinjsh

jquery un sessija

Recommended Posts

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?

Share this post


Link to post
Share on other sites


<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;

}

 

 

 

?>

Share this post


Link to post
Share on other sites

nu šādā veidā tev tiešām nekas nesanāks.. vnk beidz mocīties ar programmējamām lietām un pievērsies kaut kam mehāniskam.. piemēram adīšanai..

Share this post


Link to post
Share on other sites


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.

 

 

 

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

echo 'success';session_start();

 

Tu izvadi HTML pirms header`u izvades. Nočeko, kādu saturu Tev atgriež session.php

Share this post


Link to post
Share on other sites

<?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>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...