skip to Main Content

When I add the ajax it only runs once.

I try that when I enter a letter in the search engine or change a select field, it sends me the new search to display it on the screen.

formMenu is a form containing a select and an imput text.

 $('#formMenu').on('keyup change',function() {    
                 
         $.ajax(
                      {
                        url: '/calendar',
                        success: function( data ) {
                          $('body').html(data);
                        }
                      }
                    );
      });

2

Answers


  1. You instance of #formMenu is not existing after you replace the body even if the same element exists in the new body its still a different instance.
    You have to register the listener on the highest parent that is not replaced (in this case the body):

    $("body").on("keyup change", "#formMenu", function() {
      //ajax call
    });
    
    Login or Signup to reply.
  2. You can Try using the below.

    $(document).on('keyup change', '#formMenu', function() {
      // Your Ajax Call here
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search