Skip to content

Instantly share code, notes, and snippets.

@n8finch
Created April 3, 2018 01:07
Show Gist options
  • Select an option

  • Save n8finch/8a9a6498f1d29288e7d2844c57f4c0c0 to your computer and use it in GitHub Desktop.

Select an option

Save n8finch/8a9a6498f1d29288e7d2844c57f4c0c0 to your computer and use it in GitHub Desktop.

Revisions

  1. n8finch created this gist Apr 3, 2018.
    26 changes: 26 additions & 0 deletions XHR-for-OLO.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    /**
    * Get the Deliver store
    * @param {[type]} theLocation [description]
    * @return {[type]} Only one store location will be returned.
    */
    const getTheDeliveryStore = function( theLocation ) {

    var data = null;

    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;

    xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
    console.log(this.responseText);
    }
    });

    xhr.open("GET", "https://ordering.api.olo.com/v1.1/restaurants/near?lat=LATITUDE&long=-LONGITUDE&radius=20&limit=10&key=APIKEYHERE");
    xhr.setRequestHeader("accept", "application/json");
    xhr.setRequestHeader("access-control-request-headers", "*");
    xhr.setRequestHeader("cache-control", "no-cache");

    xhr.send(data);

    }