diff options
| author | kdam0 <kumar.damani@mail.utoronto.ca> | 2017-02-02 01:55:12 +0000 |
|---|---|---|
| committer | kdam0 <kumar.damani@mail.utoronto.ca> | 2017-02-02 01:55:12 +0000 |
| commit | e78238959da75e4574bb4bbd4dc1c4433d02785b (patch) | |
| tree | b62a9302cf1e450953d1fddc64b368727b61086b /assets | |
| parent | 98c9cbc6258f699fc944f025230c35faf8575bc2 (diff) | |
better error handling and clean up
Diffstat (limited to 'assets')
| -rw-r--r-- | assets/js/home_page.js | 32 |
1 files changed, 19 insertions, 13 deletions
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); + } } }); } |
