简体   繁体   English

用node.js表达的HTTP标头用于加载内容

[英]http headers in express with node.js for loading content

I'm working on a DHTML code playground for fun. 我正在一个DHTML代码操场上玩耍。 Right now, to pull the code that will be in the textareas from my database, I use client side javascript 现在,要从数据库中提取将在textareas中的代码,我使用客户端javascript

var currentURL = (document.URL);
var part = currentURL.split("com/")[1]; 

So this gets what's after the "com/" in my url, which should be a hash id, and stores that into the "part" variable as shown above. 因此,它将获取我URL中“ com /”后面的内容(应该是一个哈希ID),并将其存储到“ part”变量中,如上所示。 The rest of my code uses that "part" variable which is the hash id I have, and queries my db looking for the content to pull up with that matching hash id. 我的其余代码使用该“ part”变量(即我拥有的哈希ID),并查询我的数据库以查找要使用该匹配的哈希ID提取的内容。 This is fine. 这可以。 It works, however, since I'm now working with Express.js, node.js and jade, I'm wondering if I should use the request object instead so when visiting myurl.com/hashid, I then get the content from my db. 它可以工作,但是,因为我现在正在使用Express.js,node.js和jade,所以我想知道是否应该使用request对象,因此在访问myurl.com/hashid时,我便从我的网站上获取了内容。 D b。 Is using a server side solution like this better than my current solution? 使用这样的服务器端解决方案是否比我当前的解决方案更好?

If I have understood this question correctly then the answer is yes. 如果我正确理解了这个问题,那么答案是肯定的。 You should use something like req.params.hashId on server side. 您应该在服务器端使用类似req.params.hashId There is no need to extract it on client side if you only need it to query the db on server. 如果只需要它来查询服务器上的数据库,则无需在客户端提取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM