Hello everyone, help solve the task ..
How can you make a delay in a couple of seconds before receiving or showing a bot answer?
As if imitation of what bot is gaining a message.
Script brief operation:
This is a chat with a bot, ask the question you get the answer.
& lt;? php
Include ('Data.php'); // Connect an array
Include ('config.php'); // Connect to database
$ name = $ _post ["text"];
$ Respond = $ Data ["$ Name"];
// Enter SMS in the database
If (ISset ($ _ POST ['Text'])) {
$ Result = MySQL_Query ("Insert Into". $ db_table. "(Text, TextBot) Values
('$ Name', '$ Respond') ");
}
// Check messages with an array
If (! Empty ($ Data [$ Name])) {
$ respond;
}
$ sql = mysql_query ("Select` ID`, `text`,` TextBot` From `Messages` Order by
ID DESC LIMIT 10 ", $ DB); // pull out SMS from the table
? & gt;
& lt; Body & gt;
& lt; Form Method = "POST" Action = "" & gt;
& lt; div class = "Chat" & gt;
& lt; Input Type = "text" name = "text" id = "text" placeholder = "message"
class = "Message" & gt;
& lt; Button Type = "submit" class = "submit" & gt; send & lt; / button & gt; & lt; / div & gt;
& lt; / form & gt;
& lt; div class = "Chat" & gt;
& lt;? php
While ($ results = mysql_fetch_array ($ SQL)) {
Echo "& lt; div class = 'p-Text-Bot' & gt;" $ results ['TextBot']. "& lt; / div & gt; & lt; br / & gt; & lt; br / & gt;"; //
Bott answer from database
Echo "& lt; div class = 'p-text' & gt;" $ results ['Text']. "& lt; / div & gt; & lt; br / & gt; & lt; br / & gt;"; // SMS.
man from database
}
? & gt;
& lt; / div & gt; & lt; br / & gt;
& lt; / body & gt;
Answer 1, Authority 100%
& lt; head & gt;
& lt; Meta Charset = "UTF-8" & GT;
& lt; Link REL = "stylesheet" type = "text / css" href = "style.css" & gt;
& lt; script type = "text / javascript" & gt;
Window.Onload = Function () {
var i = 4;
var timer = setInterval (function () {
I--;
Document.getelementByid ('Timer'). Innerhtml = '...';
if (i == 0) {
Document.getelementByid ('Example'). style.display = 'block';
Document.getelementByid ('Timer'). style.display = 'none';
ClearInterval (Timer);
}
}, 1000)
}
& lt; / script & gt;
& lt; / Head & gt;
& lt;? php
Include ('Data.php'); // Connect an array
Include ('config.php'); // Connect to database
$ name = $ _post ["text"];
$ Respond = $ Data ["$ Name"];
// Enter SMS in the database
If (ISset ($ _ POST ['Text'])) {
$ Result = MySQL_Query ("Insert Into". $ db_table. "(Text, TextBot) Values
('$ Name', '$ Respond') ");
}
// Check messages with an array
If (! Empty ($ Data [$ Name])) {
$ respond;
}
$ SQL = MySQL_Query ("Select` ID`, `text`,` TextBot` From `Messages` Where id
NOT IN (SELECT MAX (ID) from Messages) Order by ID Desc Limit 10 ", $ db); //
Pull out SMS from the table
$ sqlall = mysql_query ("Select` ID`, `text`,` textbot` From `Messages` Order
By ID DESC LIMIT 1 ", $ db); // pull out SMS from the table
? & gt;
& lt; Body & gt;
& lt; Form Method = "POST" Action = "" & gt;
& lt; div class = "Chat" & gt;
& lt; Input Type = "text" name = "text" id = "text" placeholder = "message"
class = "Message" & gt;
& lt; Button Type = "submit" class = "submit" & gt; send & lt; / button & gt; & lt; / div & gt;
& lt; / form & gt;
& lt; div class = "Chat" & gt;
& lt;? php
While ($ results = mysql_fetch_array ($ sqlarall)) {
echo "& lt; div id = 'Timer' style = 'float: right;' & gt; & lt; / div & gt;";
echo "& lt; div id = 'example' style = 'display: none;' class = 'p-text-
Bot '& gt; "$ Results [' TextBot ']." & lt; / div & gt; & lt; br / & gt; & lt; br / & gt; "; // Bota response from database
Echo "& lt; div class = 'p-text' & gt;" $ results ['Text']. "& lt; / div & gt; & lt; br / & gt; & lt; br / & gt;"; // SMS.
man from database
}
While ($ results = mysql_fetch_array ($ SQL)) {
Echo "& lt; div class = 'p-Text-Bot' & gt;" $ results ['TextBot']. "& lt; / div & gt; & lt; br / & gt; & lt; br / & gt;";
// Bota response from database
Echo "& lt; div class = 'p-text' & gt;" $ results ['Text']. "& lt; / div & gt; & lt; br / & gt; & lt; br / & gt;"; // SMS.
man from database
}
? & gt;
& lt; / div & gt; & lt; br / & gt;
& lt; / body & gt;
Answer 2
sketched a primitive option. We hide the last message and run through time.
& lt; script type = "text / javascript" & gt;
Window.Onload = Function () {
var div = document.getelementsbyclassname ("Bot");
var Last = Div [Div.Length - 1];
var text = last.innerhtml;
last.innerhtml = '...';
SetTimeout (Function () {
last.innerhtml = text;
}, 3000);
};
& lt; / script & gt;
Answer 3
read the documentation, the function sleeep ()