如何在jQuery ajax中从div提交所有数据?

问题描述

| 我目前正在使用此脚本每秒从jQuery ajax中的record_count.PHP获取新数据,然后将其放置在notifications_load div中。但是我想知道如何让脚本将Notifications_load中的所有当前内容提交到record_count.PHP,以便可以使用
$_POST
获取数据。谁能告诉我我该怎么做?谢谢 :) 源代码
<?PHP
include(\'../general_scripts/connect.PHP\');

$or

?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<Meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /></head>
<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js\"></script>
<script type=\"text/javascript\">
var auto_refresh = setInterval(
function ()
{
$.ajax({
    url: \'record_count.PHP\',type: \'GET\',success: function(result) {
        if (result != null && result != \'\') {
            $(\'#notifications_load\').html(result);
        }
    }
});
},10000); // refresh every 10000 milliseconds

<body>
<div id=\"notifications_load\"> <?PHP
$sql=MysqL_query(\"select * from updates ORDER BY update_time DESC LIMIT 9\");
while($row=MysqL_fetch_array($sql))
{
$msg_id=$row[\'update_time\'];
$message=$row[\'item_content\'];
?>

<?PHP echo $message; ?>

<?PHP } ?> </div>

</script>
</body>
</html>
    

解决方法

我不是100%知道您要通过此操作来完成什么,但是如果您只想获取div的内容并将其提交给url,则可以执行以下操作:
function submitData(id,url) {
    var content = $(\'#\'+id).html();
    $.ajax({
        \'url\' : url,\'type\' : \"POST\",\'data\' : \'content=\'+encodeURI( content );
    });
}

submitData(\'notifications_load\',\'record_count.php\');