There was a problem using the bootstrap library. I have a modal window for adding users, there I use the drop down menu select:

<div class="tab-pane" id="addUsers"> <select name="userRol" class = "userRol"> <option class = "one"> - </option> <option class = "client">Клиент</option> <option class = "baer">Баер</option> </select></div> 

When I select all data and close the modal window, I use the .load method to reload part of the modal window:

 $('#addUserModal').on('hidden.bs.modal', function (e) { $("#addUsers").load(" #addUsers"); }) 

so that all selects return to their original state. But when I close the modal window and a part of it reloads, the following code stops working:

 $('.client').click(function(){ $.ajax({ dataType: 'json', data : { action : 'getInformUsersJsonClient' }, success : function(dataJson){ AddUsersList.onAjaxDone(dataJson); } }); }); 

although everything worked fine before rebooting.

In this case, two questions:

  1. Can someone know how to return select to its original state differently, without reloading the page or part of it?
  2. Why does $('.client').click stop after reboot?

PS: via the console, commands with $('.client') triggered, but when I look in the debugger, it does not work.

    2 answers 2

    1. When you load the page, you use $('.client').click(fun) create a listener that tracks clicks on the elements with the client class, after you reload part of the modal window, the listener crashes.

    You can correct this by creating a new listener (after a reboot) or you can add an onclick attribute to the html element, which will call the required method:

    html

     <option onclick="fun();" class = "client">Клиент</option> 

    js

     var fun = function(){ $.ajax({ dataType: 'json', data : { action : 'getInformUsersJsonClient' }, success : function(dataJson){ AddUsersList.onAjaxDone(dataJson); } }); }; 
    • Yes, this method helped me, thanks a lot for the explanation. - Casper
    • @Casper If you use the "onclick" attribute in html, do not forget to remove the listener additions from js ($ ('. Client'). Click (fun)). - grnch
    • Yes, of course I did it already)) thanks a lot) - Casper

    That's how?

     $('body').on('click', '.client', function(){ $.ajax({ dataType: 'json', data : { action : 'getInformUsersJsonClient' }, success : function(dataJson){ AddUsersList.onAjaxDone(dataJson); } }); }); 

    If the initial state of select is when nothing is selected, then reset the select, for example, like this:

    $('select').prop('selectedIndex',0);

    It is more correct to return select than to make an http request.