How to dynamically construct Backbone js collection url

Constructing Dynamic URL in backboneJS Tutorial with Example

Working on Backbone js and wanted to pass the url dynamically?

Say you want to fetch the data based on the url

url: someurl/{dynamic-value}/content/{dynamic-value}

Here are some steps to accomplish constructing backboneJS url dynamically based on runtime values.

How to select element with multiple class


Lets assume your collection looks like this

var Members=Backbone.Collection.extend({
	url: function(){
		return url+'attendees/';
	initialize: function(models, options){

On the above example your dynamic url might look like – where presenters is something you added dynamically

and on your view

var Attendees=Backbone.View.extend({
	el: 'YOUR VIEW',
	render: function(){
		var view=this;
		var member=new Members([], {group: 'presenters'});
			success: function(members){
				var template= ...YOUR STUFF GOES HERE
	events: {
		'click #activities': 'membersByActivity'
	membersByActivity: function(){
                YOUR LOGIC..
		return false;

The important part for creating dynamic url in backbone js is:

var member=new Members([], {group: 'presenters'});

where you can change the presenters part as you like dynamically

node js server downloads text/html as file on browser

Those of you who work with webserver, like apache, might already have seen that problem – like the php file that was intended to display content would be downloaded as file.. this has some fix on configuration right..
Now coming to node js, once you install the server like

  1 var http_server=require("http");
  2 http_server.createServer(function(request, response){
  3     response.writeHead(200, {'Content-Type': "text/html"});
  4     response.write("I am listening @port 8896");
  5     response.end();
  6 }).listen(8896);

This should run fine once you run node filename.js where filename.js is the file containing the above code.
but, when you try to run by going to localhost:8896 and in place of seeing the text on your browser, if the browser decided to download the file, give a a careful look at line number 3 to be sure that you have specified correct content type..