PHP变量未通过Ajax jQuery在页面上回显 [英] PHP variable not echoing on page via ajax jquery

查看:71
本文介绍了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>

这篇关于PHP变量未通过Ajax jQuery在页面上回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆