Javascript 将数据从jquery对话框传递到mysql
我有一个网站,显示了一个jQuery对话框,里面有一个Javascript 将数据从jquery对话框传递到mysql,javascript,jquery,mysql,Javascript,Jquery,Mysql,我有一个网站,显示了一个jQuery对话框,里面有一个TextArea。它还有一个保存按钮,我要做的是将数据从TextArea传递到MySQL数据库表 onEdit: function (ev, elem) { var $elem = $(elem); $('#NoteDialog').remove(); return $('<div id="NoteDialog"></div>').dialog({ title: "Note Ed
TextArea
。它还有一个保存按钮,我要做的是将数据从TextArea
传递到MySQL数据库表
onEdit: function (ev, elem) {
var $elem = $(elem);
$('#NoteDialog').remove();
return $('<div id="NoteDialog"></div>').dialog({
title: "Note Editor",
resizable: false,
modal: true,
height: "300",
width: "450",
position: { my: "left bottom", at: "right top", of: elem},
buttons: {
"Save": function () {
var txt = $('textarea', this).sceditor("instance").val();
// Put the editied note back into the data area of the element
// Very important that this step is included in custom callback implementations
$elem.data("note", txt);
$(this).dialog("close");
},
"Delete": function () {
$elem.trigger("remove");
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
},
open: function (event, ui) {
$(this).css("overflow", "hidden");
var textarea = $('<textarea id="txt" name="text" style="height:100%; width:100%;">');
$(this).html(textarea);
// Get the note text and put it into the textarea for editing
textarea.val($elem.data("note"));
textarea.sceditor({
resizeEnabled: false,
style: "jquery.sceditor.min.css",
toolbar: 'bold,italic,underline,subscript,superscript|left,center,right,justify|orderedlist,bulletlist,link,image',
width: '100%',
height: '100%'
});
},
close: function (event, ui) {
$("textarea").sceditor("instance").destroy();
}
});
onEdit:功能(ev、elem){
变量$elem=$(elem);
$('#NoteDialog')。删除();
返回$('')。对话框({
标题:“注释编辑器”,
可调整大小:false,
莫代尔:是的,
高度:“300”,
宽度:“450”,
位置:{my:“左下”,在“右上”,of:elem},
按钮:{
“保存”:函数(){
var txt=$('textarea',this.sceditor(“实例”).val();
//将编辑的注释放回元素的数据区域
//自定义回调实现中包含此步骤非常重要
$elem.data(“注释”,txt);
$(此).dialog(“关闭”);
},
“删除”:函数(){
$elem.触发器(“移除”);
$(此).dialog(“关闭”);
},
取消:函数(){
$(此).dialog(“关闭”);
}
},
打开:功能(事件、用户界面){
$(this.css(“溢出”、“隐藏”);
var textarea=$('');
$(this.html(textarea);
//获取注释文本并将其放入文本区域进行编辑
textarea.val($elem.data(“note”));
textarea.sceditor({
resizeEnabled:false,
样式:“jquery.sceditor.min.css”,
工具栏:“粗体、斜体、下划线、下标、上标|左、中、右、对齐|有序列表、项目列表、链接、图像”,
宽度:“100%”,
身高:“100%”
});
},
关闭:功能(事件、用户界面){
$(“textarea”).sceditor(“实例”).destroy();
}
});
$.ajax({
type:"POST",
cache:false,
url:"file.php",
data: {data : your_text_area_data} ,
success: function (result) {
//Write there
//If your php file sends back info, it's in the variable result
}
});
file.php
中,取回数据并查询数据库:$\u POST['data']
,然后执行查询:
INSERT/UPDATE ...
编辑:不需要像我在评论中提到的那样添加回调(我假设您的代码按原样工作),您可以在触发SAVE
按钮时添加$.ajax
:
"Save": function() {
var txt = $('textarea', this).sceditor("instance").val();
//Put the editied note back into the data area of the element
//Very important that this step is included in custom callback implementations
$elem.data("note", txt);
//$.ajax here
$(this).dialog("close");
},
那么您的代码有什么问题呢?通过ajax将数据发送到服务器script@charlietfl当点击“保存”按钮时,我需要将数据从textarea传递到mysql数据库,我指的是这个textarea(名为“text”)var textarea=$(“”);@SaifHarbia只有一个服务器脚本才能与mySql通信。关于如何实现此目的,有很多教程,请寻找一个具有与您使用的服务器语言相同的示例代码的脚本欢迎来到SO@SaifHarbia。请花些时间通读一遍,以帮助您充分利用SO。OP使用的是文本编辑器……get不适合使用字符l限制和
您的\u text\u area\u data
不会在服务器上创建请求密钥data
。我如何保证在单击“保存”按钮时完成此操作?@charlietfl根据您的建议编辑了我的文章。@Saif Harbia,您必须将此代码放入中。click()
:$(“\idOfYourSaveButton”)。单击(函数(){//点击保存按钮,做你的事});
@愉快的回答更好,但代码将进入保存
按钮的回调,不需要新的事件处理程序。对话框
已经提供了事件处理程序listener@charlietfl谢谢大家,你们的代码运行正常,但仍然有一个我无法修复的小错误。当我查看mysql数据库中存储的数据时,我发现它有stor在文本区域中插入的信息旁边添加了额外的数据。这是我得到的:kn