From e78238959da75e4574bb4bbd4dc1c4433d02785b Mon Sep 17 00:00:00 2001 From: kdam0 Date: Wed, 1 Feb 2017 20:55:12 -0500 Subject: better error handling and clean up --- assets/js/home_page.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'assets') diff --git a/assets/js/home_page.js b/assets/js/home_page.js index b04832c..059444c 100644 --- a/assets/js/home_page.js +++ b/assets/js/home_page.js @@ -23,7 +23,7 @@ function main(){ } }); - + // TODO: move this function to a general helper class?? // for auto-complete var substringMatcher = function(strs) { return function findMatches(q, cb) { @@ -45,23 +45,29 @@ function main(){ cb(matches); }; }; - // get array of all courses from controllers + + + // get array of all courses from controller $.ajax({ url: '/auto-complete-courses', type: 'GET', success: function(data){ - // console.log(JSON.parse(data)); - var states = JSON.parse(data); + var jsonData = JSON.parse(data); + if (jsonData.success) { + var states = jsonData.data; - $('.typeahead').typeahead({ - hint: true, - highlight: true, - minLength: 1 - }, - { - name: 'courseNames', - source: substringMatcher(states) - }); + $('.typeahead').typeahead({ + hint: true, + highlight: true, + minLength: 1 + }, + { + name: 'courseNames', + source: substringMatcher(states) + }); + } else { // console log the error mssg + console.log(jsonData.data); + } } }); } -- cgit v1.2.3