tj / ejs

Embedded JavaScript templates for node
4.47k stars 512 forks source link

Question: res.send() and res.render() #238

Open CrisChr opened 6 years ago

CrisChr commented 6 years ago

When I used Ajax post request to submit a form and then res.send({info: info}), but ejs can not get the info object to display. I googled and found most of them would like to use res.render() to refresh the page, but I prefer to use Ajax to implement asynchronous refresh. Anybody can help me or is there any better method?

image

image

image

Thanks

jsrj commented 6 years ago

res.send() would usually work, but the two things that stand out is your response is sent under the condition that name and pass are defined and not null. If this condition fails, the router will not send anything, causing the page to appear to be loading until it times out. If this isn’t the issue and you only want to send the info object, you can use res.JSON(info) instead.

David2913 commented 6 years ago

You could pass a callback to done and do the update yourself using jQuery when the response arrives. What do you think?

screen shot 2018-07-26 at 12 00 58 pm