For Example,
Let us take in an sql
table we have following things in a row:
I have a form where I can type an amount to store in database and also it is stored in html table. when I type a different amount then it should be stored and new row should be added with this updated value in that table.
How to achieve this using php
?
You need to create this via ajax.
n
sec. Call ajax every second and append result with message to div .js_messages
.
HTML page with ajax:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
</head>
<body>
<div class="js_messages"></div>
<script type="text/javascript">
function updateMessage() {
var $messageContainer = $('.js_messages');
$.ajax({
type: "POST",
url: "test.php",
dataType: "json",
success: function(data){
$messageContainer.append('<div class="js_messages-item">' + data.message + '</div>')
},
});
}
window.setInterval(function(){
updateMessage()
}, 1000);
</script>
</body>
</html>
PHP page:
Just generate random message for example.
<?php
echo json_encode(['message' => mt_rand()]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.