We use to add property ‘#ajax’ to a form element in our form array, to trigger an Ajax response and it works fine except in case of views exposed forms. This doesn’t work in case of views exposed forms because of some core issue: https://www.drupal.org/project/drupal/issues/2842525.
So, only option left is to implement ajax using jQuery ajax() Method and pass path of the controller function. It’s working fine.
But when using jQuery ajax() Method, an extra page gets created as we register controller function(which needs to be called on ajax trigger) in routing.yml file and response which we get is complete page instead of data returned in callback function.
When we use Drupal’s ‘#ajax’ property, no extra page gets created and it just calls the callback function.
I don’t want to create an extra page while using Ajax and want to get the data returned in callback function instead of complete page as it consumes more time. How this can be achieved?
REQUEST: Please don’t vote negative, if you are not able to understand anything then please comment. I will update the question accordingly.