Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch a collection with a search term in Backbone.js

Tags:

backbone.js

I'm trying to have a collection in backbone that calls /search/:searchTerm to the server upon fetch. I have the following line:

this.collection.fetch({ data: {searchTerm: "user input"} });

Firebug tells me this leads to a GET http://localhost:4242/search?[object%20Object] Can this only be done by writing myself the ajax call in the backbone router, or is there a smoother faster way?

like image 781
nieve Avatar asked Jul 01 '11 22:07

nieve


1 Answers

I had the same problem, but using jQuery.param seems to have fixed it, i.e.

this.collection.fetch({ data: jQuery.param({searchTerm: "user input"}) });
like image 142
Dan Brooke Avatar answered Nov 03 '22 05:11

Dan Brooke