Fixed the errors in ajax and template rendering

Got help from Brandon Conway