From 0953f703efd879aa7009f16d938502289c4b0ab5 Mon Sep 17 00:00:00 2001 From: Denise L'Hirondelle Date: Tue, 16 Aug 2016 16:54:53 -0400 Subject: [PATCH 1/2] #27 This is supposed to get me JSON, not a status code of 0 --- app/assets/javascripts/meetup.js | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 app/assets/javascripts/meetup.js diff --git a/app/assets/javascripts/meetup.js b/app/assets/javascripts/meetup.js new file mode 100644 index 0000000..ebef0e9 --- /dev/null +++ b/app/assets/javascripts/meetup.js @@ -0,0 +1,57 @@ +$(document).ready(function() { + function createCORSRequest(method, url) { + var xhr = new XMLHttpRequest(); + + if ("withCredentials" in xhr) { + + // Check if the XMLHttpRequest object has a "withCredentials" property. + // "withCredentials" only exists on XMLHTTPRequest2 objects. + xhr.open(method, url, true); + + } else if (typeof XDomainRequest != "undefined") { + + // Otherwise, check if XDomainRequest. + // XDomainRequest only exists in IE, and is IE's way of making CORS requests. + xhr = new XDomainRequest(); + xhr.open(method, url); + + } else { + + // Otherwise, CORS is not supported by the browser. + xhr = null; + + } + return xhr; + } + + function getApiData() { + //TODO: Why is xhr empty? + + //var url = 'https://api.meetup.com/pitonneux/events'; //production + var url = 'https://api.meetup.com/2/events?key=ABDE12456AB2324445&group_urlname=ny-tech&sign=true'; //test + + var xhr = createCORSRequest('GET', url); + + if (!xhr) { + throw new Error('CORS not supported'); + } + + xhr.onload = function() { + var allTheData = xhr.getResponseText; + console.log("At least it loaded"); + return allTheData; + }; + + xhr.onerror = function() { + //throw new Error('Woops, there was an error making the request.'); + throw new Error(xhr.statusText); + }; + + xhr.send(); + } + + var eventsList = getApiData(); + + //TODO: Do stuff with data + +}); From 1dfb6ab25002fe42f475164a3fe03edb1c0b6fa3 Mon Sep 17 00:00:00 2001 From: Denise L'Hirondelle Date: Tue, 23 Aug 2016 14:23:43 -0400 Subject: [PATCH 2/2] #27 new script can now access meetup event info --- app/assets/javascripts/meetup.js | 61 ++++++-------------------------- 1 file changed, 11 insertions(+), 50 deletions(-) diff --git a/app/assets/javascripts/meetup.js b/app/assets/javascripts/meetup.js index ebef0e9..6750533 100644 --- a/app/assets/javascripts/meetup.js +++ b/app/assets/javascripts/meetup.js @@ -1,57 +1,18 @@ -$(document).ready(function() { - function createCORSRequest(method, url) { - var xhr = new XMLHttpRequest(); - - if ("withCredentials" in xhr) { - - // Check if the XMLHttpRequest object has a "withCredentials" property. - // "withCredentials" only exists on XMLHTTPRequest2 objects. - xhr.open(method, url, true); - - } else if (typeof XDomainRequest != "undefined") { - - // Otherwise, check if XDomainRequest. - // XDomainRequest only exists in IE, and is IE's way of making CORS requests. - xhr = new XDomainRequest(); - xhr.open(method, url); - - } else { - - // Otherwise, CORS is not supported by the browser. - xhr = null; +$(document).ready(function() { + function addScript(src) { + console.log(src); + var s = document.createElement( 'script' ); + s.setAttribute( 'src', src ); + document.body.appendChild( s ); } - return xhr; - } - function getApiData() { - //TODO: Why is xhr empty? - - //var url = 'https://api.meetup.com/pitonneux/events'; //production - var url = 'https://api.meetup.com/2/events?key=ABDE12456AB2324445&group_urlname=ny-tech&sign=true'; //test - - var xhr = createCORSRequest('GET', url); - - if (!xhr) { - throw new Error('CORS not supported'); + window.gotIt = function(data) { + alert(data.data[0].created); + $('#results').append('Got... something'); } - xhr.onload = function() { - var allTheData = xhr.getResponseText; - console.log("At least it loaded"); - return allTheData; - }; - - xhr.onerror = function() { - //throw new Error('Woops, there was an error making the request.'); - throw new Error(xhr.statusText); - }; - - xhr.send(); - } - - var eventsList = getApiData(); - - //TODO: Do stuff with data + addScript('https://api.meetup.com/pitonneux/events?photo-host=public&page=10&sig_id=195641644&sig=3c9a7b49b18362a2e7f49adb63e161d4f6da4ec3&callback=gotIt'); }); +