我用nodejs做了个网页应用,作用是读取并修改xml文档,但是现在非常囧的发现并不会将文档保存。。。
xml文档是用js读取的,文档内容保存在变量xmlDoc里面,注意这里只是html文档的变量并不是nodejs的全局变量。
那么现在应该怎么将这个xmlDoc保存?
现在两个想法分别是将xmlDoc设置成全局变量或者通过restful框架将xmlDoc上传并接受,然后通过fs保存。
但是前者实测html并不能直接使用node的全局变量,后者要求是要用js进行自动上传,即使用js进行超链接而不是通过按钮,完全不会写啊OTZ,哪位大神能解决求顺便捎上一两行代码QUO
先谢谢了
I don’t quite understand the problem mentioned by the poster. First of all, the project is a Web project. The js environment of the front-end browser and the js environment of the back-end node are different. Variables cannot be shared. The front-end uploads data through the HTTP protocol, and the back-end obtains data. It is obtained from the request object. For example, the front-end uses Ajax to upload a string in post mode:
$.post('/postData',{xnldoc:'12345'}).done()
If the back-end node framework uses express, In the router, you can write router.post('postData',function(req, res, next){var doc=req.params('xnldoc');});
and you will get it.