Php 数组不使用ajax post

Php 数组不使用ajax post,php,ajax,post,Php,Ajax,Post,除了我的阵列之外,一切都很好。当我点击发送的计数($a)停留在1。 $catbotreply是我的消息的回复 $a=array(); array_unshift($a,$catbotreply); <script> $(document).ready(function () { $("#submit").on("click", function (event) { event.preventDefault();

除了我的阵列之外,一切都很好。当我点击发送的
计数($a)
停留在1。
$catbotreply
是我的消息的回复

$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>
$a=array();
数组_unshift($a,$catbotreply);
$(文档).ready(函数(){
$(“#提交”)。在(“单击”)上,功能(事件){
event.preventDefault();
$.ajax({
类型:“POST”,
url:“index.php”,
数据:$(“#catbot”).serialize()+“&d=d”,
成功:功能(数据){
控制台日志(数据);
$('#catbotResult').html(数据);
}
});
});
});
如果(isset($_POST['msg'])){
$response.=“您说:”.stripslashes($usermessage)。“

”; $response.='Bot:'.$catbotreply.

; $response.=计数($a); 回音$应答; }
您应该更改在ajax中发送数据的方式

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

$_POST['catbot'];
$_POST['d'];

使用
$.JSON.Parse(data)
解析数据
$a
中有什么?$a是我的数组,用于保存我的上一个msgw您在哪里将值压入
$a
@使用unshift时,我也尝试了push,但我更喜欢从数组的一开始就知道
$(“#catbot”)中有什么问题。serialize()+”&d=d“
作为op ha仅捕获
msg
?可以同时发送对象和名称-值对数据