简体   繁体   English

使用jQuery保存模式弹出数据

[英]Save the modal popup data using jQuery

Here I have a popup window with one text area and 2 dropdown index. 在这里,我有一个带有一个文本区域和2个下拉索引的弹出窗口。 In popup window user needs to enter data. 在弹出窗口中,用户需要输入数据。 Then this data has to be stored in given path. 然后,必须将这些数据存储在给定的路径中。

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>

Table design for modal popup: 模态弹出表设计:

<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>

And having a button with "savefile" id. 并有一个带有“ savefile” id的按钮。

Here is the Button code: 这是按钮代码:

<button runat="server" id="Saveasfile" class="btn btn-primary" OnClick="saveasfile()">Save </button>

By clicking the "Save" button the user should save the data which is entered in the table rows. 通过单击“保存”按钮,用户应保存在表行中输入的数据。

While clicking the "Save" button it is closing automatically. 单击“保存”按钮时,它会自动关闭。 While debugging it is showing like "No element found". 调试时,它显示为“找不到元素”。

What should I do? 我该怎么办?

Html ids should be case sensitive in most browsers, as far as I know. 据我所知,HTML ID在大多数浏览器中应区分大小写。 You have 你有

Saveasfile 另存文件

and are trying to get 并试图获得

saveasfile 保存文件

.Ajax can not write your data in to file. .Ajax无法将您的数据写入文件。 To write your data in to the file you need to write server side code. 要将数据写入文件,您需要编写服务器端代码。 Or you can use ActiveXObject in jquery. 或者,您可以在jquery中使用ActiveXObject。 eg: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM