Answer the question
In order to leave comments, you need to log in
Jquery. How to fix the problem with constant execution of received Javascript from Php?
Good afternoon.
I agree, the title of the question can be confusing, but I'll try to explain))
var username = "";
var user = "Пользователь"
var botname = "Бот";
function send_message(conv,message){
if (conv.length > 4) {
conv = conv + "<br>";
}
$("#converse").html(conv +"<script></script><div class='message-box left-img'><div class='picture'><img src='img/a.png' title='user name'></div><div class='mes'><span class = 'current-msg'>" + "<span id='chat-bot'>" + botname + ": </span><p>" + message + "</p></span></div></div>");
$(".current-msg").hide();
$(".current-msg").delay(500).fadeIn(function() {
$(".current-msg").removeClass("current-msg");
var e = document.getElementById('converse');
e.scrollTop=e.scrollHeight
})
}
function get_username(conv){
send_message(conv,"Привет, могу ли я чем то помочь?");
}
function ai(conv,message){
// $("#send").click(function(){
$.get("get.php", {q:message}, function(data, status){
// alert("Data: " + data + "\nStatus: " + status);
send_message(conv,data);
});
console.log('Я всё');
// });
}
$(function(){
var open = false;
var conv = $("#converse").html();
get_username(conv);
$("#send").click(function(){
var usermsg = $("#textbox").val();
conv = $("#converse").html();
console.log(conv.length);
if (usermsg != "") {
$("#textbox").val("");
if (conv.length > 4) {
conv = conv + "<br>";
}
$("#converse").html(conv + "<div class='message-box right-img'><div class='picture'><img src='img/user.png' title='user name'></div><div class='mes'><span><span id='chat-user'>" + user + ": </span><p>" + usermsg + "</p></span></div></div>");
$("#converse").scrollTop($("#converse").prop("scrollHeight"));
conv = $("#converse").html();
ai(conv,usermsg);
}
});
$("#chat-button").click(function(){
$("#chat-box").animate({"right":"0px"});
});
$("#cancel").click(function(){
$("#chat-box").animate({"right":"-300px"});
});
});
document.forms.sendtext.addEventListener("submit", function (e) {
e.preventDefault();
var text = this.elements.text.value;
$("#send").click();
});
document.forms.onkeyup = function(event) { // слушаете событие onkeyup формы
if (event.keyCode == 13) { // коли enter - дёргаете вашу штатную функцию отправки
buttonOtprav2();
}
};
function buttonOtprav2() {
console.log('enter is firing');
event.preventDefault();
}
Привет => include '/script/privet.php'
Пока => include '/script/poka.php'
<?php
блаблабла
?>
<script>
alert('бла бла бла')
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question