我如何...在jquery中注册Session变量并在其他页面上将其检索。 [英] How do I.. Register Session variable in jquery and retrive it on other page..
问题描述
亲爱的先生,
我正在php中创建一个聊天项目,所以我想通过jquery和ajax方法注册会话变量
我的注册变量代码..
Dear Sir,
I am making a chat project in php so i want to register session variable through jquery, and ajax method
My Code for Registering variable..
var postdata = 'username=' + username + '&password=' + password + '&first=' + first + '&last=' + last + '&mobile=' + mobile + '&email=' + email + '&dob=' + dob + '&gender=' + gender;
jQuery.ajax({
type: 'POST',
url: 'http://localhost/group/php/register.php',
data: postdata,
cache: false,
success: function(){
$.post("php/redirecting.php",
{"username":username});
window.location.replace('http://localhost/group/profile.html');
}
});
php文件代码redirecting.php
php file code redirecting.php
<?php
session_start();
$uname = $_POST['username'];
$_SESSION['user'] = $uname;
?>
下一页profile.html i想从数据库中追溯价值...
jquery文件
Next page profile.html i want to retrive value from database...
jquery file
$(document).ready(function(){
getval();
});
function getval()
{
$.ajax({
type:"GET",
url:"http://localhost/group/php/profileedit.php",
success: function(result)//,var email,var mobile,var dob
{
$("#fname").val(result);
}
});
};
profileedit.php
profileedit.php
<pre><?php
if(isset($_SESSION['user']))
{
$uname = $_SESSION['user'];
}else
{
die('Could not connect: ' . mysql_error());
}
$link = mysql_connect('localhost','root','');
if (! $link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("groupchat",$link) or die('couldnt able to connect db');
$sql = "select fname,lname from users where username = '$uname'";
$result = mysql_query($sql,$link);
if(! $result)
{
die('Could not get data:'. mysql_error());
}
$row = mysql_fetch_array($result);
echo trim($row['fname']);
echo trim($row['lname']);
mysql_close($link);
?>
但是在文本框中它无法追溯价值从会话变量,如它没有在会话中注册,但当我手动给它值,它从数据库成功检索值并填写文本框...
请帮助....建议我...提前谢谢..
but here in the text box it could not retrive value from session variable like its not registering in session but when i give value manually its successfully retrieve value from database and fill in textbox...
please help.... suggest me ...thanks in advance..
推荐答案
.post( php / redirecting.php,
{ 用户名跨度>:用户名});
window 。 location .replace(' http://localhost/group/profile.html');
}
});
.post("php/redirecting.php", {"username":username}); window.location.replace('http://localhost/group/profile.html'); } });
php文件代码redirecting.php
php file code redirecting.php
<?php
session_start();
uname =
uname =
_POST [' 用户名'];
_POST['username'];
这篇关于我如何...在jquery中注册Session变量并在其他页面上将其检索。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!