Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think your plugin is related to the issue you are seeing.</p> <p>Your code initiates an Ajax call <strong>on every keystroke</strong>.</p> <p>Hence, upon multiple keystrokes, you're then receiving multiple responses one after another, some of which may or may not be empty, which explains the "toggling" effect you're seeing.</p> <p>What I assume you really want is to only handle the final Ajax <strong>once, only after the user has stopped typing</strong>. Or to say it differently, there should only be one active Ajax request "per purpose" upon any given time.</p> <p>Hence, you will need to have a reference to the initial Ajax call, and abort it on subsequent keystrokes, then initiate a new one.</p> <pre><code>jQuery(document).ready(function() { var xhr; jQuery('.qty').keyup(function() { var qty = jQuery(this).val(); var pid = jQuery(this).next().html(); var element = this; // abort the Ajax request invoked by previous keystrokes if (xhr) xhr.abort(); xhr = jQuery.post('shopping_cart_ajax.php', {products_id: pid, products_quantity: qty}, function(data) { if (data) { jQuery(element).tooltip(); jQuery(element).unbind('mouseenter mouseleave'); jQuery(element).tooltip('update', data); jQuery(element).tooltip('show'); } else { jQuery(element).tooltip('destroy'); } }); }); }); </code></pre> <p>For your reference, <code>.post()</code> returns a jqXHR object <a href="http://api.jquery.com/jQuery.post/" rel="nofollow">(http://api.jquery.com/jQuery.post/)</a>, which exposes the <code>abort()</code> method <a href="http://api.jquery.com/jQuery.ajax/#jqXHR" rel="nofollow">(http://api.jquery.com/jQuery.ajax/#jqXHR)</a></p> <p>For Ajax calls especially those that are invoked by hovering, or in your case, keystrokes, this is the sort of routine I would always keep in mind: i.e. aborting previous Ajax calls.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload