显示PHP回响在使用AJAX / jQuery的一个textarea? [英] Display PHP echo in a textarea using AJAX/jQuery?

查看:233
本文介绍了显示PHP回响在使用AJAX / jQuery的一个textarea?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示使用Ajax的自动刷新每一秒textarea的一个PHP的回声。到目前为止,我所做的一切,这并不需要工作,我什么也没得到,在textarea的。

I am trying to display a PHP echo in a textarea using AJAX that auto refreshes every second. So far everything I do this doesn't want to work and I get nothing in the textarea.

下面是我的code:

<?php
$stmt = mysqli_prepare($db_conx,"SELECT message FROM chat WHERE asker = ?");
$stmt->bind_param('s', $asker);

 $stmt->execute();
$stmt->bind_result($message);

/* fetch values */

while ($stmt->fetch()) {
    $currvalue[] = array('message'=>$message);
}

echo $message;

echo '333333333';
?>

HTML code:

HTML code:

<textarea id="chattercontent" style="width:90%; height:150px; resize:none;" readonly></textarea>

AJAX / jQuery的code:

AJAX/jQuery code:

   <script type="text/javascript">
    $(document).ready(function () {

        function load() {
            $.ajax({ //create an ajax request to load_page.php
                type: "GET",
                url: "file.php",
                dataType: "text", //expect html to be returned                
                success: function (response) {
                    $("#chattercontent").html(response);
                    setTimeout(load, 1000)
                }
            });
        }

        load();
    });
    </script>

与code,会发生什么上面,我得到的回声'333333333'; 在我的文字区域,像这样 333333333 这是很好的和精细。但我不明白的回声$信息; 在我的文字区域

What happens with the code above, I get the echo '333333333'; in my textarea like so 333333333 which is good and fine. But I don't get the echo $message; in my textarea.

我已经检查,看看是否MySQL表和列,如果看到它不是空的,我可以确认它不是空的,它具有一定的价值在里面。

I have checked to see if the MySQL table and column to see if its not empty and I can confirm that it is not empty and it has some values in it.

我也,直接观看的为file.php 页从浏览器和它回声$ user_message数据; 正确。但它不会回荡在AJAX调用,并在我的文本区域。

I also, viewed the file.php page directly from the browser and it does echo $user_message; properly. But it doesn't get echoed in AJAX call and in my textarea.

可能有人请告知这个问题?

Could someone please advise on this issue?

推荐答案

您$消息变量没有被anywere分配

Your $message variable is not being assigned anywere

替换您的回音$消息;与

replace your echo $message; with

print_r($currvalue);

,你会看到你的输出。

and you will see your output.

在换句话说,$消息变量包含什么! (与 $消息='成才'分配给它的东西;

In other words, you $message variable contains nothing! (assign it something with $message = 'someting';)

这篇关于显示PHP回响在使用AJAX / jQuery的一个textarea?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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