2016-04-27 1 views
0

"新規作成"オプションでドロップダウンしています。ユーザーが[新規作成]オプションをクリックすると、ポップアップウィンドウに保存ボタンが表示されます。そのポップアップウィンドウで、ユーザーはデータを入力し、ユーザーはこのデータをサーバーに保存します。jQueryを使用してポップアップデータを保存する

これは、データをポップアップで保存するためのjQuery関数です。

<script type = "text/javascript" > 
    function savefile() { 

    $(document).ready(function() { 
     $('#Savefile').click(function() { 
     $.ajax({ 
      url: 'D:\C#.Net\Scramble.txt', 
      datatype: "json", 
      method: 'post', 
      data : scrtabledata, 
      success: function() { 
      var scrtabledata = $('#modaltable'); //Table ID 
      scrtabledata.empty(); 
      $(data).each(function() { 
       scrtabledata.append('<tr><td>' + scrtabledata.comment + '</td><td>' + scrtabledata.DropDownList2 + '</td><td>' + scrtabledata.DropDownList1 + '</td></tr>'); 
      }); 
      } 
     }); 
     }); 
    }); 
    }; 
</script> 

そして、このようにそのスクリプトを渡し、

<button runat="server" id="Savefile" class="btn btn-primary" onclick="savefile()">Save </button> 

これは、jQueryのポップアップ用のコードです:

<script type="text/javascript"> 
$(function() { 
     //Attach click event to your Dropdownlist 
     $("#<%= DropDownConfigFile.ClientID %>").change(function() { 
      //Get the selected valu of dropdownlist 
      selection = $(this).val(); 
      //If its one then show the dialog window. You can change this condition as per your need 
      if (selection == 1) { 
       //Show the modal window 
       $('#myModal').modal('show'); 

      } 
     }); 
    }); 
</script> 

ユーザーが「保存」ボタンをクリックすると、データがその中に格納することがあります与えられたパス。何も実行していません。 「保存」ボタンをクリックすると自動的に閉じます。この問題を解決するために私を助けてください。

このコードに誤りがありますか?

+0

更新

<input type="text" id="userId"/> <input type="text" id="userData"/> var userID=$('#userId').val(); var userData=$('#userData').val(); $(document).ready(function() { $('#Savefile').click(function() { $.ajax({ url: 'D:\C#.Net\Scramble.txt', datatype: "json", data : { id:userID, info:userData }, method: 'post', success: function() { var scrtabledata = $('#modaltable');//Table ID scrtabledata.empty(); $(data).each(function() { scrtabledata.append('<tr><td>' + scrtabledata.comment + '</td><td>' + scrtabledata.DropDownList2 + '</td><td>' + scrtabledata.DropDownList1 + '</td></tr>'); }); } }); }); }); }; 

場合 ように考慮しなければならない

。クリックしてください( –

+0

をすることができますあなたのポップアップとjs –

+0

Javaスクリプトのコードを教えてください。

0

は、あなたはそれを保存するために、Ajaxの機能にそのデータを渡す必要があります。

$(document).ready(function() { 
       $('#Savefile').click(function() { 
        $.ajax({ 
         url: 'D:\C#.Net\Scramble.txt', 
         datatype: "json", 
         data : Your Data to be passed, 
         method: 'post', 
         success: function() { 
          var scrtabledata = $('#modaltable');//Table ID 
          scrtabledata.empty(); 

          $(data).each(function() { 
           scrtabledata.append('<tr><td>' + scrtabledata.comment + '</td><td>' + scrtabledata.DropDownList2 + '</td><td>' + scrtabledata.DropDownList1 + '</td></tr>'); 
          }); 

         } 

        }); 
       }); 
      }); 
     }; 

ここで、データ属性には、データをキー値のペアとしてjson形式で渡す必要があります。

var myData={"id":"1","Name":"Test"} 

このようにして、独自のJSONを作成し、それをajax関数に渡すことができます。あなたは、あなたがjQueryの$( '#SAVEFILE')を使用して、クリック機能をtriggreingているので、onclickの機能を使用したくない

+0

私はここにはいませんでした。渡される "。どのデータをここに渡す必要があります。ユーザーが入力する詳細はわからないからです。 – kiran

関連する問題