简体   繁体   English

在成功jQuery上刷新div

[英]refresh div on success jquery

I would simply like to refresh the content of the div on success. 我只想在成功时刷新div的内容。 The content inside the div is a php code which retrieves records from the database. div中的内容是一个php代码,可从数据库中检索记录。 I tried the below but the div just disappears and nothing is being refreshed. 我尝试了以下内容,但div消失了,并且没有任何刷新。 Can someone help me out? 有人可以帮我吗?

<div class="div_wrap">
<?php
$stmt = $db->prepare("select * from inbox where username = ? and id = ?");
$stmt->bind_param('ss', $username, $id);//the vars are already defined.
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc())
{
echo $row['message'];
echo $row['date'];
}
?>
</div>

<script>
var dataString = 'message='+ message + '&subject='+ subject;
    $.ajax({
        type: "POST",
        url: "message.php",
        data: dataString,
        cache: false,
        beforeSend: function() {
            $("#errormsg").html('<div style="padding-left:120px;">Please wait<img src="image/loader.gif" alt="Loading...." align="absmiddle" title="Loading...."/></div><br clear="all">');

        },
        success: function(response) {
            $('.div_wrap').html(response);
        }
    });
</script>

First, your div should look like this: 首先,您的div应该如下所示:

<div class="div_wrap">

</div>

Then, for your ajax success function to load the content into the div , your php should return the html code it self, something like this: 然后,为使ajax成功函数将内容加载到div ,您的php应该返回自身的html代码,如下所示:

echo "table><tr><td>Super content</td></tr></table>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM