Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJAX and Fetch API on this plug-in without using jQuery? #76

Open
martinrios95 opened this issue Nov 5, 2018 · 1 comment
Open

AJAX and Fetch API on this plug-in without using jQuery? #76

martinrios95 opened this issue Nov 5, 2018 · 1 comment

Comments

@martinrios95
Copy link

Referencing #65 and #61

I'm testing this plug-in with Vue-Resource, XHR and Fetch API.
Have you got an example for this JavaScript's vanilla library without using third-party frameworks for requesting REST API's?

@mohsentaleb
Copy link

I've used it with a Tiny AJAX library (1KB) called NanonAJAX. Example:

var xhr;
var autoCompelete = new autoComplete({
  selector: "#searchbox",
  minChars: 2,
  cache: false,
  delay: 0,
  source: function(term, response) {
    try {
      xhr.abort();
    } catch (e) {}
    xhr = nanoajax.ajax(
      {
        url: "queryURL"
      },
      function(code, res) {
        var json = JSON.parse(res);
        if (typeof json != "undefined") {
          if (json.results) response(json.results); // my json has a `results` key
        }
      }
    );
  },
  renderItem: function(item, search) {
    // Your rendering goes here.
  }
});

P.S. The reason behind using xhr variable is that I needed to abort the request if user has a new key stroke and the AJAX call for the previous query should be aborted. This is very important when you have delay getting data from your server and avoids displaying irrelevant results for a query string.

This was referenced Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants