I am trying to implement a search function for my site. When a user enters a search query foobarinto a field inputand sends it, he is redirected to http://mydomain.com/search?query=foobar.
Problem :: . How can I grab the GET parameters queryfrom a URL and send it to the server and get an array of results back as a JSON response? Should I do it like this?
My current attempt below does not trigger the function search.
the router
var AppRouter = Backbone.Router.extend({
routes: {
'search?query=:query': 'search'
},
search: function(query) {
this.photoList = new SearchCollection();
var self = this;
this.photoList.fetch({
data: {query: query},
success: function() {
self.photoListView = new PhotoListView({ collection: self.photoList });
self.photoListView.render();
}
});
}
});
var app = new AppRouter();
Backbone.history.start({
pushState: true,
root: '/'
});
source
share