javascript - How to get my dynamically created div to show up on page after ajax call -


i have project trying implement jquery. have add button, everytime clicked, create new record on in database. trying figure out how ajax call recognize new data , display on screen, without me having manually refresh screen, hoping use fadein or similar show new div.

this checklist system,so can edit checklist adding steps on fly , reorder existing steps wrote loaddata function loop through records , append appropriate data, not sure how auto refresh div when adds new step. don't want reload entire page, newly created div.

$(function() {    loaddata();  });  // drag , drop steps , update database  $('#steps').sortable({    update: function(event, ui) {      var data = $(this).sortable('serialize');        data = data + '&id=' + json.idchecklist + '&ver=' + json.version;      $.ajax({        data: data,        type: 'post',        url: '../processes/reorder.php',        success: (function() {})        });      }  });    //load data  function loaddata() {    $.ajax({      url: '../json/test.php',      type: 'get',      datatype: 'json',      success: function(data) {        json = data        $('#details').find('h2').html(data.idchecklist);        $('#details').find('h4').html(data.status);        $.each(data, function(k, v) {            if (k == "steps") {            count = 1;            $.each(v, function(key, value) {              $('#steps').append('<span>' + count + '</span><div id=step' + value.idstep + '>' + value.steptext + '</div>');              count++;              text[count] = value.steptext;            })          }        })        }    })  }  //add new step  $('#add').click(function() {    console.log(count);    div = $('#step-' + count);    $.ajax({      type: 'post',      data: {        id: json.idchecklist,        ver: json.version,        step: count      },      url: '../processes/addstep.php',      success: (function() {          div.fadein('fast')        })    })    })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>  <div class="jumbotron"></div>  <div id="details">    <h2></h2>    <h4></h4>  </div>  <div id="steps">    </div>  <button id=add value="add">add</button>


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -