question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any way to make ajax dynamic ?

See original GitHub issue

Hi, I managed to get youtube results autocomplete using JSONP like that:

function jsonp(url, callback) {
var callbackName = 'jsonp_callback_' + Math.round(100000 * Math.random());
window[callbackName] = function(data) {
    delete window[callbackName];
    document.body.removeChild(script);
    callback(data);
};

var script = document.createElement('script');
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName;
document.body.appendChild(script);
}

jsonp('http://suggestqueries.google.com/complete/search?hl=en&q=MYQUERY&client=youtube', function(data) {
    var list = [];
    for (var i = 0; i < data[1].length; i++) {
        list.push(data[1][i][0]);
    }
    console.log(list);
    new Awesomplete(document.querySelector("#search"),{list:list});
});

But there’s a little problem, I want MYQUERY to change on keypress and this way, reload the list content with new data. Is this possible ? Thanks.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:4
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
mercmobilycommented, Oct 5, 2018

Isn’t this a perfect solution?

https://github.com/LeaVerou/awesomplete/issues/16892#issuecomment-223066074

var a = new Awesomplete(myInput, myOptions);
myInput.addEventListener('input', function() {
    var list = getNewListWithAjax();
    a.list = list;
    a.evaluate();
});
3reactions
chhuangcommented, Oct 3, 2016

@ralienpp I think that’s because you are creating a new instance of Awesomplete everytime you hit a key. Try setting up Awesomplete before your ajax call and outside your keyup event, and then just update list inside the the ajax call.

  var awesomeStuff = new Awesomplete(document.querySelector("#ajax-example input"));

  function run_elasticSearch (value){
    ...
    ajax.onload = function() {
      values =  JSON.parse(ajax.responseText);
      list = values.hits.hits;
      list_name = list.map(function(i) { 
      return i._source.name; });
      console.log(list_name);

      awesomeStuff.list = list_name;
    };
    ...
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create dynamic ajax function? - Stack Overflow
$.ajax({ url: 'file.php', type: 'POST', async: ...
Read more >
Simple Dynamic JavaScript Ajax Function - CodeProject
Using only one function AjaxCall() enables dynamic functionality to run Ajax on webPages. It allows beginners to run Ajax code on any web ......
Read more >
How to Create Dynamic Web Content with JavaScript and AJAX
Start by learning how to make AJAX requests using JavaScript coding examples. Then connect to JSON data and external files, and use the...
Read more >
how to get the dynamic variable from the URL into the ajax url ...
how to get the dynamic variable from the URL into the ajax url string? ... I'm a bit stuck, any help is gratefully...
Read more >
Dynamic Content Load using jQuery AJAX - Phppot
jQuery AJAX Dynamic Content Loading. This jQuery function receives page id and sends it to PHP a page via an AJAX request. With...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found