aboutsummaryrefslogtreecommitdiff
path: root/assets/js/home_page.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js/home_page.js')
-rw-r--r--assets/js/home_page.js32
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);
+ }
}
});
}