Bootstrap 4.1.3 modal body retains jquery returned data. How to clear cache for each new request?

馋奶兔 提交于 2019-12-02 07:52:45

问题


I have a form that submits data via jquery which is then shown via bootstrap modal.

However, the problem is that, if I quickly try to give new values to the form then the modal body sometimes doesn't show freshly calculated values but shows the old cached values.

How can I destroy the modal cache data in bootstrap 4 ? I have tried various bootstrap3 tips but it just wouldn't work and I still see old cached data intermittantly.

Here is what I tried.

  $('#modalForm').on('hidden.bs.modal', function () {
      $('#modal_content').empty();
      $('#modalForm').modal('dispose');
      $(this).find('form').trigger('reset');
      $(this).find('form')[0].reset();
      //$('.modal').remove(); // this prevents future modals
  });

Any help would be greatly appreciated.


回答1:


It might be a binding issue, you are binding hidden.bs.modal on the #modalForm so unless you don't unbind it at some point, the same code will always execute with old values.

Try unbinding it by putting this code $('#modalForm').off('hidden.bs.modal') right before $('#modalForm').on('hidden.bs.modal', function () {[...] and if it doesn't work you might want to bind it only once using the $('#modalForm').one('hidden.bs.modal') instead.



来源:https://stackoverflow.com/questions/56136200/bootstrap-4-1-3-modal-body-retains-jquery-returned-data-how-to-clear-cache-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!