gpt4 book ai didi

javascript - 如何使用ajax函数更新数据库

转载 作者:行者123 更新时间:2023-11-29 13:00:25 25 4
gpt4 key购买 nike

我有一个包含从数据库中提取的客户信息的表。在此表的最后一列中,我有一个编辑按钮,可以打开一个弹出窗口,其中包含文本字段,其中数据库值作为占位符。我希望用户能够更改文本字段中的值,然后将这些新值保存到数据库中。

我使用以下 jQuery 函数来调用弹出窗口:

<script>
$('#mypopup').dialog({
autoOpen: false,
modal: 'true',
minHeight: '300px',
minWidth: '300px',
buttons: {
'Save Changes': function(){
$.ajax({
url: 'ext/to/my/file.php',
type: 'POST',
data: $(this).find('form').serialize(),
success: function(data){
//some logic to show that the data was updated
//then close the window
$(this).dialog('close');
}
});
},
'Discard & Exit' : function(){
$(this).dialog('close');
}
}
});

$('.edit').click(function(e){
e.preventDefault();
$.ajax({
url: 'ext/to/my/file.php',
type: 'GET',
data: "id="+$(this).parent().next('td').text(), //send some unique piece of data like the ID to retrieve the corresponding user information
success: function(data){
//construct the data however, update the HTML of the popup div
$('#mypopup').html(data);
$('#mypopup').dialog('open');
}
});
});
</script>

这是我的第一篇文章,所以我不确定我需要了解多少具体内容。被调用的 php 文件基本上只是一个显示正确数据库信息的表单。如果需要任何其他信息,请告诉我!提前致谢!

最佳答案

您应该只编辑“保存更改”功能。在显示“ext/to/my/file.php”的地方,您应该放置将数据保存到数据库的 php 文件。现在是这样,php函数将接收一个包含所有编辑信息的序列化对象。从那里,只需将其保存到数据库即可。希望对您有帮助!

关于javascript - 如何使用ajax函数更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23430374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com