PHP变量未通过Ajax jQuery在页面上回显
我的代码有问题,因为使用Ajax jquery时页面上没有回显我的php变量.这是我的代码...
I am having a problem with my code as my php variable is not being echoed on page when using ajax jquery. Here is my code...
<script>
function refresh_div() {
$('.loader').show();
var username = "<?php echo $user; ?>";
jQuery.ajax({
type: "POST",
url: "load.php",
data:{user : username},
success:function() {
jQuery("#load_msgs").append(response+'<br>');
},
complete: function(){
$('.loader').hide();
}
});
}
t = setInterval(refresh_div,1000);
</script>
我正在尝试将用户名"发送到页面网址"load.php" ...我这样称呼,但没有回声...
i am trying to send "username" to page url "load.php"... i called it this way but nothing is being echoed...
if(isset($_POST['user'])) {
echo $_POST['user'];
}
请帮忙,谢谢... :)
pls help out thanks... :)
已编辑...
当我尝试使用此代码时,即在这样的成功函数中添加传递响应作为参数...
when i tried using this code i.e adding passing response as parameter in success function like this ...
<script>
function refresh_div() {
$('.loader').show();
var username = "<?php echo $user; ?>";
jQuery.ajax({
type: "POST",
url: "load.php",
data:{user : username},
success:function() {
jQuery("#load_msgs").append(response+'<br>');
},
complete: function(){
$('.loader').hide();
}
});
}
t = setInterval(refresh_div,1000);
</script>
....每秒显示一次数据(用户名)..像眨眼之间切换页面...我该如何使数据静态显示以便在ajax页面上使用变量.谢谢:)
.... the data (username) gets displayed every second.. like a blink toggling on and off the page... how do i make the data display static in order to use the variable on the ajax page. Thanks :)
您错过了成功功能的响应. 试试这个:
You missed response in success function. Try this:
<script>
function refresh_div() {
$('.loader').show();
var username = "<?php echo $user; ?>";
jQuery.ajax({
type: "POST",
url: "load.php",
data:{user : username},
success:function(response) {
$("#load_msgs").append(response+'<br>');
},
complete: function(){
$('.loader').hide();
}
});
}
t = setInterval(refresh_div,1000);
</script>