简体   繁体   English

“在使用Express的Node.js服务器中没有方法'getscript'”

[英]“has no method 'getscript'” in Node.js server using Express

I have a server in Node.js and I use Express to make a web app. 我在Node.js中有一台服务器,我使用Express制作一个网络应用程序。 My server (app.js) gets data from a form (by Ajax post method) and I want that it proceeds this data by using the code of another file (anotherfile.js). 我的服务器(app.js)从表单中获取数据(通过Ajax post方法),我希望它通过使用另一个文件的代码(anotherfile.js)来继续这些数据。

I used this solution: https://stackoverflow.com/a/950146/3303704 and I included this code in my app.js file: 我使用了这个解决方案: https ://stackoverflow.com/a/950146/3303704我把这个代码包含在我的app.js文件中:

app.post('/', function(req, res) {

$.getScript("anotherfile.js", function(){
alert("Script loaded and executed.");
});

});

But Node.js returns me that "has no method 'getscript'". 但是Node.js告诉我“没有方法''得到''''。

Idea of the cause and solution? 理由和解决方案? Thanks! 谢谢!

You appear to be trying to use jQuery in node. 您似乎试图在节点中使用jQuery。

The solution you have linked to is a solution for front-end. 您链接的解决方案是前端解决方案。

Use require() in node. 在节点中使用require()

Try reading this article: Node.js, Require and Exports . 尝试阅读本文: Node.js,Require和Exports It explains that for instance if you define this in one file called user.js : 它解释了,例如,如果您在一个名为user.js文件中定义它:

var User = function(name, email) {
  this.name = name;
  this.email = email;
};
module.exports = User;

You can do this in another: 你可以在另一个:

var user = require('./user');

var u = new user.User();

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

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