javascript - return false in AJAX call disabling php update -


i have following script having issues $("#success") fadeout , delay. thought figured out, when have return false; not commented out, php script doesn't work. when commented out ajax call works , php file supposed do, fadeout , delay doesn't work.

does have ideas why happening?

 <script>     $(document).ready(function(){      $('.approve').click(function(){         $.ajax({            url: 'userrequest_approve.php',            type: 'post',            data: {             id: $(this).val(), //id             status: 'approved' //status            },            success: function(data) {             //do data got returned              $("#success").fadein();                  $("#success").show();                  $('#success').html('user status changed!');                  $('#success').delay(5000).fadeout(400);            },            //type: 'post'         });     //return false;     });     }); </script> 

update: source code added form

    <form action="" method="post" id="status">              <input type='hidden' name='id' value='33' id='pending_id'/> name - hgfd hgd</br>username - testttttt</br></br>      </form>                          <button class="approve" type="submit" form="status" name="approve" value="33">approve</button>                         <button id="deny" type="submit" form="status" name="deny" value="denied">deny</button><br><br><br>         <form action="" method="post" id="status">              <input type='hidden' name='id' value='23' id='pending_id'/> name - boo boo</br>username - boopbfd</br></br>     </form> 

you need wait response server using promise. "await" response server code execute code "after" response returned server.

<script> $(document).ready(function(){  $('.approve').click(function(){     var promise = $.ajax({        url: 'userrequest_approve.php',        type: 'post',        data: {         id: $(this).val(), //id         status: 'approved' //status        }     });      promise.then(function(data){         $("#success").fadein();              $("#success").show();              $('#success').html('user status changed!');              $('#success').delay(5000).fadeout(400);     }); }); 

});


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -