alexgorbatchev / jquery-textext

A super awesome, customizable text input supporting tags, autocomplete, ajax and other goodness in a crazy cool a-la cart way.
http://textextjs.com
MIT License
1.27k stars 201 forks source link

ajax + autocomplete : two ajax calls are sent #145

Open bizantom opened 10 years ago

bizantom commented 10 years ago

Hi,

here is my code :

$('#location').textext({
   plugins : 'autocomplete ajax',
   autocomplete: {
       dropdownMaxHeight : 'auto'
   },
   ajax : {
    url : 'myurl',
        dataType : 'json',
    cacheResults : false,
    delay: 1
   }
});

And that's what happens : the first time I enter a keyword, two ajax calls are sent :

<myurl>?q=keyword

and

<myurl>?q=

so the requested suggestions appear and then disappear. After that, if I modify the keyword, everything goes well. The problem occurs only the first time.

I have a fix but don't know if it is the good way to do it. In the method onShowDropdown of the autocomplete puglin, I replaced :

 if(!suggestions)
    return self.trigger(EVENT_GET_SUGGESTIONS);

by

if(!suggestions && !self.core().hasPlugin('ajax'))
      return self.trigger(EVENT_GET_SUGGESTIONS);

What do you think about this?

Thanks in advance,

Thomas

mirindraulki commented 7 years ago

Hi bro,i don't know if you can see this but have you find the anwser of your problem but i have the same problem and i don't know how to solve it,thanks if you remembered the anwser,

Thanks

Mirindra

bizantom commented 7 years ago

Hi Mirindra,

as said in the description of the issue, I found a solution. It consists in modifying the onShowDropdown function. You can see the fix in the pull request #146

Hope that helps,

Thomas

mirindraulki commented 7 years ago

thank you very mauch bro,it's working i change too my configuration and it's work

===> the old

$('#local') .textext({ plugins : 'autocomplete tags ajax', ajax : { url : '<?php echo $path ;?>boost/ajax/geo.php', dataType : 'json', typeDelay : 0.5, loadingMessage : 'Chargement...', loadingDelay : 0.5, cacheResults : false,

        }
    });

===> the new

$('#local') .textext({ plugins : 'autocomplete tags ajax', autocomplete: { dropdownMaxHeight : 'auto' }, ajax : { url : '<?php echo $path ;?>boost/ajax/geo.php', dataType : 'json', typeDelay : 0.5, loadingMessage : 'Chargement...', loadingDelay : 0.5, cacheResults : false, delay: 1 } });

thank you very much,you are the only who have discussed about this topic during two day of research,thanks,thanks

Mirindra

bizantom commented 7 years ago

You're welcome!