Closed davidsilva closed 9 years ago
With the help of a friend, I solved the problem:
var com = com || {}; com.apress = com.apress || {}; com.apress.model = com.apress.model || {};
com.apress.model.Search = Backbone.Model.extend({
url: 'http://localhost:8080/search',
rootUrl: 'http://localhost:8080/search',
sync: function(method, model, options) {
if (this.get('query')) {
this.url = this.rootUrl + '/' + this.get('query');
}
Backbone.sync.call(this, method, model, options);
},
parse: function(model) {
return model;
}
});
By having this.url = this.url + ... subsequent queries were being concatenated -- and thus failing.
Thanks for spotting this! I will update the source
Hi, James,
I hope you can help me with this. Search works correctly the first time but subsequent search queries are appended to the URL in the API call (they don't appear in the browser URL, though). For example, here's this console output:
Run search against keith SearchView.js:31 search for keith AppRouter.js:26 XMLHttpRequest cannot load http://localhost:8080/search/keith/keith. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
I think the problem is in the AppRouter.