ejs

Node JS : Error with res.download() after res.render()

徘徊边缘 提交于 2019-12-11 06:19:09
问题 I'm beginning with Node JS, and I get an error : Error: Can't set headers after they are sent. You can see my code, the problem is with res.download() ; Or, how can I show the view without res.render() ? Can you tell me how to fix this issue? Thanks you! var express = require('express'); var app = express(); var pythonShell = require('python-shell'); app.set('view engine', 'ejs'); app.use(express.static('style')); app.post('/downloads', function(req, res) { res.render('downloads.ejs');

How to switch between indexes on fetched data in ejs?

[亡魂溺海] 提交于 2019-12-11 06:14:47
问题 I have sent object array to the front end and I would like it to switch the displayed data between indexes 0 and 1 (uniTimes[0]<->uniTimes[1]), every 5 minutes or so. How can I make this happen, is it only possible by using external frameworks like React/Angular? **//Array** var uniTimes = [ { lectures: [ { title: "Information System Security", classroom: "503a.", start: "1995-12-17T08:00:00", end: "1995-12-17T09:15:00" }, { title: "Project Management", classroom: "117a.", start: "1995-12

Cradle / Express / EJS convert html to its entities

*爱你&永不变心* 提交于 2019-12-11 06:07:20
问题 I'm using Cradle with Express and EJS on my blog. Maybe i am missing smth but some of them converts html entities to its equivalents. I have html in doc.quote field and after this piece of code it changes quotesDb.view('list/by_date', { 'startkey' : {}, 'endkey' : null, 'descending' : true }, function(err, res) { if (err) { r.send(); return; } r.partial('quotes', {'quotes' : res}, function(err, str) { console.log(str); sendResponse('content', str); }); }); quotes.ejs: <% for (var i=0; i

Sailsjs view caching (bug ?)

一世执手 提交于 2019-12-11 04:17:42
问题 I was rendering a view using res.view('layout', {my: 'Object'}) . Peculiar Behaviour: When I changed the ejs file and refreshed the browser, the change was visible (without server restart). BUT If my object contained a truthy value of property cache , like so: res.view('layout', {my: 'Object', cache: true}) then, I open the view in the browser, all's good. But if I change the ejs file now, the changes do not show in the browser on refresh, unless server is stopped and re-lifted. Is there any

EJS Variable Throws Error Even Though It Renders Properly

人盡茶涼 提交于 2019-12-11 03:37:53
问题 I have an array of objects I am trying to iterate through in an ejs template, but I keep getting "Reference Error: bills is not defined". Other StackOverflow questions said to test whether or not the variable was actually defined, so I used <h1><%= bills.length %></h1> This properly renders the length of the array, but it still throws an error at ReferenceError: /index.ejs:11 9| <div id="billCarousel" class="carousel slide" data-ride="carousel"> 10| <!--Indicators--> >> 11| <h1><%= bills

Why is request.body undefined?

依然范特西╮ 提交于 2019-12-11 03:08:48
问题 I have a node-js server which includes bodyparser and everything: var express = require('express'); var dbcon = require('./app/db/databaseconnection'); var bodyParser = require('body-parser'); var app = express(); var router = express.Router(); var filepath = __dirname + '/views/'; app.set('view engine', 'ejs'); app.use(express.static(__dirname + '/public')); app.use('/', router); app.use(bodyParser); app.use(bodyParser.json()); // support json encoded bodies app.use(bodyParser.urlencoded({

How can I set a meta description tag in Sailsjs using ejs templates?

好久不见. 提交于 2019-12-11 02:44:06
问题 I would like to be able to set the description meta tag from the sails controller action. I have searched all over, but the only example involves the page title. This is my first node.js and sailsjs site, am I going about this the wrong way? Something like this: module.exports = { index: function (){ res.view( { title: 'The Title Text', metaDescription: "The Description Text" }); } }; 回答1: Yes, this is correct. You can insert in your template with <!DOCTYPE html> <html> <head> <title><%=

How to refresh table data using Ajax, Json and Node.js

时间秒杀一切 提交于 2019-12-11 02:32:03
问题 I'm using Node.js as server-side with express and Twitter Bootstrap as front-end. The page has a dialog with a form and a submit button; the form is submitted through Jquery Ajax call for don't reload the page after the response from node.js server. Here are three steps would like I to do: page.ejs <table id="tblProgs" class="table table-bordered table-hover table-striped dataTable"> <thead> <tr> <th> Column </th> </tr> </thead> <tbody> <% datas.forEach(function(data) { %> <tr> <th width="15%

How to include static files in express js

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 01:43:53
问题 I am using the the express js framework with node js and in my server.js file , i have used app.use('/api',router); In my ejs file , when i use a script tag <script src = main.js> I get an error "Cannot get http://localhost:3000/api/main.js" How can i include these files in the ejs please help!!! 回答1: You can use express.static middleware app.use('/public', express.static('directory/containing/your/files')); The parameter of express.static is the path to the directory containing all your

How to render ejs from jQuery?

自闭症网瘾萝莉.ら 提交于 2019-12-10 23:35:37
问题 I want to render a file after getting the data from the API. code $(document).ready(function() { $(document).delegate( "#editUser", "click", function() { var userId = $(this).data('id'); $.post("/userProfile",{"userId":userId},function(data, status){ console.log(data); //gets data here //how to render ejs file here with the above data? }); }); ejs file: (sample.ejs) <% include header.html %> <strong>Sample ejs</strong> <ul> <li><%= data.name %> says: <%= data.message %></li> </ul> <% include