문제

I have a server in Node.js and I use Express to make a web app. 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).

I used this solution: https://stackoverflow.com/a/950146/3303704 and I included this code in my app.js file:

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

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

});

But Node.js returns me that "has no method 'getscript'".

Idea of the cause and solution? Thanks!

도움이 되었습니까?

해결책

You appear to be trying to use jQuery in node.

The solution you have linked to is a solution for front-end.

Use require() in node.

Try reading this article: Node.js, Require and Exports. It explains that for instance if you define this in one file called 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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top