[英]I got a div with data from the server, with ajax the div will be replaced with a form that i submit with jquery and ajax to a php route
[英]How do i submit all data from a div in jQuery ajax?
我當前正在使用此腳本每秒從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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.