我想创建一个Feed / Facebook样式,其中Feed会在更新新条目后自动更新。到目前为止,我已经有了这个:
<form id="submitEvent">
<textarea placeholder="Suggest an event!"></textarea>
<a class="button" id="newEvent" href="#">Submit</a>
<script>
$('#newEvent').click(function(e) {
sugEvent = $('textarea').val();
user = $('#userName').text();
var data = "user=" + user + "&newEvent=" + sugEvent;
$.ajax({
data: data,
url:"uploadInfo.php",
success:function(result)
{
$("#otherSuggestedEvents").load(updateEvents.php);
$('#otherSuggestedEvents').show();
}
});
$('textarea').val("");
});
</script>
<div id="otherSuggestedEvents"></div>
updateEvents.php:
<?php
$hostname= -censored-;
$username=-censored-;
$password=-censored-;
$dbname=-censored-;
$conn = mysqli_connect($hostname, $username, $password, $dbname);
$results = mysqli_query($conn, "SELECT * FROM `suggestedEvents` ORDER BY `time` DESC");
while($row = mysqli_fetch_array($results))
{
$username = $row['user'];
$event = $row['newEvents'];
echo "<div id='userEvents'>";
echo "<p>$event</p>";
echo "<h3>-$username</h3>";
echo "</div>";
}
?>
表单可以很好地更新数据库,但<div id="otherSuggestedEvents"></div>
只是空的。我不知道出了什么问题,任何帮助都会受到赞赏!
答案 0 :(得分:0)
尝试检查来自load()调用的响应,如
$("#otherSuggestedEvents").load("updateEvents.php", function(response, status, xhr) {
if (status == "error") {
alert("error: " + xhr.status + " " + xhr.statusText);
}
});
希望这会对你有所帮助。