0

I am developing an application with node.js, express, couchDB and using nano to communicate with couch. I am using a jquery get request from client javascript. Using fiddler i can see that i get my view in the RAW result but the view is never rendered.

client:

$.get('employee/'+customerId, function(data){
        return;
    });

route:

app.get('/employee/:id', employee.viewEmployee);

viewEmployee:

exports.viewEmployee = function(req, res){
    db.get(req.params['id'], { revs_info: false }, function(err, body, header) {
        res.render('employee/single', {employee: body});
    });
};

Everything works with no errors and i get the 'employee/single' view html in the raw response. my question is why the view is not rendered? why is the html just sent back in the raw and how can i get this to work?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
limlim
  • 395
  • 1
  • 6
  • 14
  • I replaced the jquery get with: window.location = '/employee/'+customerId; and it now works, but i still cant wrap my head around why the get doesnt do the job – limlim Oct 17 '12 at 17:15

2 Answers2

2

Your $.get call is using a call back that isn't doing any thing.

from the jQuery api examples

$.get("test.php",
   function(data){
     $('body').append( "Name: " + data.name ) // John
              .append( "Time: " + data.time ); //  2pm
   }, "json");

Shows you how to do this.

Erin
  • 2,407
  • 18
  • 21
0

You are doing an ajax call.

try console.log(data) inside your $.get callback, are you seeing the html you expect?

chovy
  • 72,281
  • 52
  • 227
  • 295
  • yes have get the html i expect but the jade view i have created is not rendered. I have continued with using window.location instead of the $.get and the application is behaving as expected now. – limlim Oct 17 '12 at 20:44
  • use type: 'html' in your ajax call. – chovy Oct 17 '12 at 23:49