I try to insert data using Jquery and I textbox and select options
Html
- <input type="text" class="input-sm" id="txt_repeat" />
- <select id="dura_values">
- <option>da(s)</option>
- <option>We(s)</option>
- </select>
JQUERY
- <script type="text/javascript">
- $(function () {
- $('[ID*=btn_Add]').on('click', function () {
- debugger;
- var frequency = $('#txt_repeat').val();
- var duration = $('#dura_values').val();
- debugger;
- var obj = {};
- obj. frequency= frequency;
- obj. duration= duration;
- insert(obj);
- });
- });
- });
- $(function insert(obj) {
- $.ajax({
- type: "POST",
- url: "Maintenance.aspx/Insert_master_services",
- contentType: "application/json;charset=utf-8",
- data: "{ frequency:'" + obj. frequency + "', duration:'" + obj. duration+"'}",
- success: function (result) {
- var insert = JSON.parse(result.d).response;
- },
- error: function (Error) {
- alert(Error);
- }
- });
- });
- </script>
But problem is how when I insert data successfully then how I display that data in table
- <table id="master_table" class="table table-striped table-bordered" style="width: 100%;" cellspacing="0">
- <thead></thead>
- <tbody></tbody>
- </table>
First I manually enter data in datatabse table and I generate table through jquery like this
- <script type="text/javascript">
- $(function () {
- $.ajax({
- type: "POST",
- url: "Maintenance.aspx/master_Services",
- contentType: "application/json;charset=utf-8",
- dataType: "json",
- success: function (result) {
- debugger;
- var m = JSON.parse(result.d).response;
- debugger;
- var master = $('#master_table').DataTable({
- "dom": 'Blfrtip',
- "columns": [
- {
- "title": "Frequency",
- "title": "Frequency",
- "visible":false
- },
- {
- "title": "Freq_Du",
- "data": "Freq_Du",
- "visible":false,
- "render":function(data,type,row)
- {
- return row.frequency+row.Freq_Du+row.Freq_Mil
- }
- },
- ]
- });
- debugger;
- for(var i=0;i<m.length;i++)
- {
- if (m[i] !== null)
- {
- master.row.add({
- "frequency": m[i][1],
- "Freq_Du": m[i][2],
- })
- }
- }
- master.draw();
- },
- error: function (error) {
- debugger;
- var r = error.responseText;
- var errorMessage = r.Message;
- alert(errorMessage);
- alert(r);
- alert(Error);
- }
- });
- });
- </script>