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?