【问题标题】:Save the modal popup data using jQuery使用 jQuery 保存模式弹出数据
【发布时间】:2016-05-03 12:28:21
【问题描述】:

这里我有一个带有一个文本区域和 2 个下拉索引的弹出窗口。在弹出窗口中,用户需要输入数据。然后这些数据必须存储在给定的路径中。

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 有 OnClick="saveasfile()" ?删除它。
  • 还有,你的网址很奇怪,不能写D:\Scramble.txt...无效
  • 我已更改该 URL 并删除了 OnClick="saveasfile()"。还是不行,先生
  • 我从来没有说过它会解决它:)
  • 您需要一个服务器来处理您的 POST 并保存数据

标签: javascript jquery


【解决方案1】:

据我所知,在大多数浏览器中,Html id 应该区分大小写。你有

另存为文件

并且正在尝试获得

保存文件

【讨论】:

    【解决方案2】:

    .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();
        }
    

    【讨论】:

      猜你喜欢
      • 2021-06-09
      • 2018-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多