使用jQuery保存模式弹出数据
Save the modal popup data using jQuery
这里有一个弹出窗口,其中有一个文本区域和两个下拉索引。在弹出窗口中,用户需要输入数据。然后这些数据必须存储在给定的路径中。
jQuery
$("#saveasfile").click(function () {
var customer = {};
customer.name = $("[id*=comment]").val();
customer.scramble = $("[id*=DropDownList2]").val();
customer.confirm = $("[id*=DropDownList1]").val();
$.ajax({
type: "POST",
url: "D:'Scramble.txt",//path
data: JSON.stringify(customer),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
$('#myModal').dialog("close");//modal popup window
// alert("Record inserted successfully.");
}
});
});
</script>
模式弹出的表格设计:
<textarea class="form-control" id="comment"></textarea>
</td>
<td>
<div class="dropdown">
<asp:DropDownList ID="DropDownList2" runat="server" CssClass="selectpicker">
<asp:ListItem Text="Alpha-Numeric Scramble" />
<asp:ListItem Text="Packed-Decimal Scramble" />
<asp:ListItem Text="Date-Time Scrambler" />
</asp:DropDownList>
</div>
<div class="dropdown">
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="selectpicker">
<asp:ListItem Text="Yes" />
<asp:ListItem Text="No" />
</asp:DropDownList>
还有一个带有"保存文件"id的按钮。
这是按钮代码:
<button runat="server" id="Saveasfile" class="btn btn-primary" OnClick="saveasfile()">Save </button>
单击"保存"按钮,用户应保存在表格行中输入的数据。
单击"保存"按钮时,它将自动关闭。调试时,它显示为"未找到元素"。
我该怎么办?
Html-ids在大多数浏览器中应该区分大小写。你有
另存为文件
并试图获得
保存为文件
。Ajax无法将数据写入文件。要将数据写入文件,您需要编写服务器端代码。或者您可以在jquery中使用ActiveXObject。例如:
$(#saveData").click(function(){
customer.name = $("[id*=comment]").val();
customer.scramble = $("[id*=DropDownList2]").val();
customer.confirm = $("[id*=DropDownList1]").val();
writeToFile(customer.scramble, customer.confirm,);
});
function writeToFile(scramble, confirm){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.OpenTextFile("D:'Scramble.txt", 8, false, 0);
fh.WriteLine(scramble+ ',' + confirm);
fh.Close();
}
相关文章:
- 数据属性仅在切换设备模式下工作
- Ember数据:DS.EmbeddedRecordsMixin的预期使用模式
- 如何在模式框中显示ajax调用返回的数据
- 将图像文件存储在猫鼬模式中的二进制数据中,并以html形式显示图像
- 使用mongoose将数据推送到mongoDB模式中的数组中
- 使用jQuery保存模式弹出数据
- 用于筛选无模式集合的最快数据结构
- 使用Angular not Binding引导模式绑定数据
- 挖空和显示模块模式的数据绑定问题
- 我无法从引导模式中清除表单数据
- 无法销毁引导模式数据
- twitter引导模式——如何将数据传递给回调函数
- 在引导模式中,点击相应的datatables行中的按钮,填充数据
- JSON数据应该覆盖JSON模式吗?(通过jdorn/json编辑器使用模式和数据)
- PHP根据用户选择的项目以模式加载数据
- angularjs设计模式和从服务器获取数据的最佳实践
- PHP-Jquery-简单模式的开放数据
- 将JSON数据注入AngularJS引导模式
- 数据模式样式,应该'name'对象的键或属性
- HandsOnTable -如何在数据模式中使用行头