doumi6685 2011-04-15 22:09
浏览 91
已采纳

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

I am currently using this script to get new data every second from record_count.php in jQuery ajax then place it in the notifications_load div. But i am wondering how i can get the script to submit all the current content in notifications_load to record_count.php so i can use a $_POST to get the data. Can anyone tell me how i can do this? Thanks :)

Source code:

<?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>
  • 写回答

1条回答 默认 最新

  • douliu8327 2011-04-15 22:20
    关注

    I'm not 100% sure what you're trying to accomplish by doing this, but if all you want to do is grab the contents of a div and submit it to a url, you could do this:

    function submitData(id, url) {
        var content = $('#'+id).html();
        $.ajax({
            'url' : url,
            'type' : "POST",
            'data' : 'content='+encodeURI( content );
        });
    }
    
    submitData('notifications_load','record_count.php');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置