duanhui1869 2015-11-16 03:56
浏览 20
已采纳

数组不使用ajax帖子

everything work good except my array. when i click few time on sent the count($a) stay at 1. $catbotreply is the reply of my msg.

$a=array();
array_unshift($a,$catbotreply); 

 <script>
    $(document).ready(function () {
        $("#submit").on("click", function (event) {
            event.preventDefault();
            $.ajax({
                type: "POST",
                url: "index.php",
                data: $("#catbot").serialize() + "&d=d",
                success: function (data) {
                    console.log(data);
                    $('#catbotResult').html(data);
                }
            });
        });
    });
</script>



 if (isset($_POST['msg'])) {





   $response.= ' <b class="yousay">You say:</b>' . stripslashes($usermessage) . '<br /><br />';
$response.= '<b class="catbotsays">Bot:</b>' . $catbotreply . '<br /><br />';
 $response.= count($a);              
echo $response;
}






     <form name="catbot" id="catbot" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="POST">
                    <b>Msg:</b>
                    <input type="text" name="msg" size="30" class="text">
                    <input type="submit" id="submit" name="submit" value="Send!" class="bttn">
                    <input type="text" name="lastcatbot" value="<?php echo $simplecatbot; ?>">
                    <input type="text" name="lastwascomm" value="<?php echo $command; ?>">
                </form>

                <hr>
                <div class="leftalign" id="catbotResult">
                    <b class="yousay">You say:</b>Connected!<br /><br />
                    <b class="catbotsays">Bot:</b>Connected!<br /><br />
                </div>

before i add the ajax function i was using a hidden text to save my last msg and i understand if i use echo in the same page the data won't refresh so its why i added the count($a) to $response. my msg and bot reply refresh at every msg but my count stay at 1 . anyone know why?

  • 写回答

1条回答 默认 最新

  • dqysi86208 2015-11-16 03:59
    关注

    You should change the way you are sending the data in ajax.

    data: {catbot:$("#catbot").serialize() ,d:"d"},
    

    And receive as

    $_POST['catbot'];
    $_POST['d'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?