Friday, 12 May 2017

Can't render data using Mustache in ajax call

I am using mustacheExpress to render files it's working well but...

app.set('views', __dirname + '/views'); //look for files to render in views directory
app.engine('html', mustacheExpress()); //Render the files using mustache
app.set('view engine', 'html'); //The extension of the file is .html
app.use(express.static(path.join(__dirname, 'webapps')));

res.render('customers/list.html', {
        state : true,
        data : {
            FirstName : 'Stephen',
            LastName : 'Neel'
        }
    });

});

When using ajax call and render dynamically mustache not working

var apiURL = 'http://here I gave my url to access';
$(function() {
    console.log("haha");
    console.log("scr1 run");
    $.ajax({
        url : apiURL + '/getteams',
        type : 'GET',
        success : function(response) {
            console.log("ajax working", response);
            var output = $("#output");
            var template = $("#test1").html();
            var html = Mustache.render(template, response);
            output.append(html);
        },
        error : function(err) {
            alert('Error');
        }
    })
});

But this ajax rendering working when only I changed from this

app.engine('html', mustacheExpress()); 

to this

app.engine('html', require('ejs').renderFile);

But this time rendering data from server file not working! What is the use of that renderFile? I thought that is missing in when setting app.enging in mustacheExpress but that also not working...Which one is used to renderFile in mustacheExpress????



via valavan

No comments:

Post a Comment