0

我想创建一个提要 Facebook/twitter 样式,其中提要在更新新条目后自动更新。到目前为止,我有这个:

<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>

更新事件.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>只是空的。我不知道出了什么问题,任何帮助将不胜感激!

4

1 回答 1

0

尝试检查 load() 调用的响应,例如

$("#otherSuggestedEvents").load("updateEvents.php", function(response, status, xhr) {
  if (status == "error") {
    alert("error: " + xhr.status + " " + xhr.statusText);
  }
});

希望这会帮助你。

于 2013-08-08T08:43:16.930 回答