Home > front end >  How do I make the ajax run?
How do I make the ajax run?

Time:10-11

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);
                        }
                      }
                    );
      });

CodePudding user response:

You can Try using the below.

$(document).on('keyup change', '#formMenu', function() {
  // Your Ajax Call here
})

CodePudding user response:

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
});
  • Related