簡體   English   中英

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

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

我在Node.js中有一台服務器,我使用Express制作一個網絡應用程序。 我的服務器(app.js)從表單中獲取數據(通過Ajax post方法),我希望它通過使用另一個文件的代碼(anotherfile.js)來繼續這些數據。

我使用了這個解決方案: https ://stackoverflow.com/a/950146/3303704我把這個代碼包含在我的app.js文件中:

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

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

});

但是Node.js告訴我“沒有方法''得到''''。

理由和解決方案? 謝謝!

您似乎試圖在節點中使用jQuery。

您鏈接的解決方案是前端解決方案。

在節點中使用require()

嘗試閱讀本文: Node.js,Require和Exports 它解釋了,例如,如果您在一個名為user.js文件中定義它:

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

你可以在另一個:

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

var u = new user.User();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM