Javascript 如何实时更新页面并保存jquery更新
我用的是这个代码Javascript 如何实时更新页面并保存jquery更新,javascript,php,jquery,Javascript,Php,Jquery,我用的是这个代码 <form id="love" name="love" method="post" onsubmit="return false"> Name: <input id="name" type="text" name="name"><br> <input type="submit" name="submit"> </form> <table class="table table-bordered" i
<form id="love" name="love" method="post" onsubmit="return false">
Name: <input id="name" type="text" name="name"><br>
<input type="submit" name="submit">
</form>
<table class="table table-bordered" id="update">
<thead>
<th>User</th>
<th>Bet Amount</th>
<th>Payout</th>
<th>Game</th>
<th>Roll</th>
<th>Profit</th>
</thead>
<tbody>
<script type="text/javascript">
$("#love").submit(function() {
$.ajax({
type: 'GET',
url: 'response.php',
data: { username: $('#name').val() },
success: function (data) {
$("#update").prepend(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
});
</script>
</tbody>
</table>
名称:
使用者
下注金额
支出
游戏
卷
利润
$(“#爱”).submit(函数(){
$.ajax({
键入:“GET”,
url:'response.php',
数据:{username:$('#name').val()},
成功:功能(数据){
$(“#更新”).prepend(数据);
},
错误:函数(xhr、ajaxOptions、thrownError){
警报(thrownError);
}
});
});
//Response.PHP
<?php
$username = $_GET['username'];
echo "<tr>";
echo "<td>$username</td>";
echo "</tr>";
?>
这段代码的作用是,当有人输入一个查询时,表中会添加一个具有他输入的名称的新行。问题是,
谢谢首先,您需要修改Response.php以包括以下内容:
注意:我刚刚描述了如何实现解决方案的概念,您需要自己编写代码。如果你仍然面临这个问题,请告诉我 使用服务器上的数据库,并将答案发布到它。Thansk。但是有没有一种不使用数据库的方法呢?如果您愿意,这种方式可能会变得非常消耗资源,您可以将数据存储在JSON文件或XML文件中,然后跳过使用数据库。好的,我将测试它,过一会儿再返回给您。从现在开始吃午饭什么的
$username = isset($_GET['username'])? $_GET['username'] : NULL;
if($username) {
//save new user to database
}
//STEP2. pick all the users from database
//STEP3. return all the users obtained from Databse.
?>
$.ajax({
type: 'GET',
url: 'response.php',
data: {},
success: function (data) {
$("#update").html(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});