使用jquery,ajax和php将div中的更新数据保存到数据库

时间:2022-10-22 23:35:22

I have a div that contains table rows and columns of a spreadsheet (I am using http://jquerysheet.googlecode.com/svn/branches/3.x/jquery.sheet.html), on button click i use ajax to fetch the contents in the div by the id into the database. Problem is when i update the spread sheet and saves, it doesn't send the updated content to the database. It rather sends the default content.

我有一个div包含电子表格的表行和列(我使用的是http://jquerysheet.googlecode.com/svn/branches/3.x/jquery.sheet.html),点击按钮我使用ajax来获取div中的内容由id进入数据库。问题是当我更新电子表格并保存时,它不会将更新的内容发送到数据库。它宁愿发送默认内容。

Button

<a href='#' id="fat-btn" class="btn btn-info" data-loading-text="Saving, Please Wait ..."> Save Sheet </a>

Jquery / Ajax

$('#fat-btn').click(function() {

            var content = $('#sheetParent').html();

            $.ajax({
                url: 'sendtodatabase.php',
                type: 'POST',
                data: {
                    content: content
                }
            });
        });




    });

sendtodatabase.php

<?php

require_once("conn.php");

$resval=$_REQUEST['content'];

$ins=mysql_query("update tabula set sheet='$resval' where id='5'")or die(mysql_error());

?>

Div

<div id="sheetParent">    

<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

</table>

Can anyone help me on how to get the updated div contents into the database? NOTE: Im a novice.

任何人都可以帮助我如何将更新的div内容添加到数据库中?注意:我是新手。

1 个解决方案

#1


0  

The div you are trying to put into database does not contain the data you want to save, it's rendered in a new element (i recommend having a look at the actual source of your sheet, you'll see there's a lot going on (jSUI, etc.). Have you tried this event?

你试图放入数据库的div不包含你要保存的数据,它是在一个新的元素中呈现的(我建议看一下你工作表的实际来源,你会发现有很多事情要发生(jSUI)等等。你有没有尝试过这个活动?

sheetSave: function(e, jS, tables) 

'tables' being one of the parameters should give you the data you're looking for. hth

'tables'是其中一个参数,可以为您提供所需的数据。心连心

#1


0  

The div you are trying to put into database does not contain the data you want to save, it's rendered in a new element (i recommend having a look at the actual source of your sheet, you'll see there's a lot going on (jSUI, etc.). Have you tried this event?

你试图放入数据库的div不包含你要保存的数据,它是在一个新的元素中呈现的(我建议看一下你工作表的实际来源,你会发现有很多事情要发生(jSUI)等等。你有没有尝试过这个活动?

sheetSave: function(e, jS, tables) 

'tables' being one of the parameters should give you the data you're looking for. hth

'tables'是其中一个参数,可以为您提供所需的数据。心连心