Skip Navigation

[Resolved] Ajax Search – Update results while typing (which callback to use?)

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 5 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1162795

I know that you mentioned earlier that it might be a performance issue to have live update on inputs so this live update is not implemented by default, but performance is not a problem in my scenario.

What I want to achieve is to have a live update on each keypress/ keyup (best would be to have at least two characters for the update results function to fire) andalso to redirect to the /search url on pressing the "enter key".

The last part works, but I struggle to find the callback to update the ajax results list on "keyup".

jQuery(document).ready(function($) {
   
//update results when typing (THIS PART LACKS THE UPDATE RESULTS CALL also it should only fire if the input is longer than 2) 
  $('#myinput').keyup(function() {
    
//UPDATE AJAX RESULTS
    
  })
  
  
//redirect to search on pressing enter (THIS PART WORKS)
  $('#myinput').keypress(function (e) {
    var code = e.keyCode ? e.keyCode : e.which;
    if (code.toString() == 13) {
      redirectotosearch(); // call the function to redirect to another page
      return false;
    }
  });

  // Function that redirect the user to another page
  function redirectotosearch() {
    window.location = "/searchpage";
  }

  
});

Thanks in advance for any help!!!!

#1162839

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Konstantin

I'm not sure what other conversations you have had about this.

I take it you are talking about a View, and you want the View results to update as the user types into a search field.

It is not as simple as finding the right callback to use.

The search inputs are in a form, and updating the results—even via ajax—means updating the entire form, and the resulting ajax update replaces the current form as well as the View results.

I don't think what you want can be done using Views, it will require a custom solution for ajax submissions after each key press and handling of the returned matching posts to populate the results.

This is outside of our support policy, I'm afraid.

I can point you to tutorials about using ajax in the context of WordPress, such as hidden link

You could use the API function render_view in your code to generate the results of the View query as HTML (see https://toolset.com/documentation/programmer-reference/views-api/#render_view).

If it is not something you can implement, you could try the list of Toolset Contractors: https://toolset.com/contractors/