我正在寻找一种方法,允许用户在特定功能完成运行后才能点击链接。在我的情况下,我有一个ejs模板,其中包含两个链接。点击第一个链接(“运行python”)会激活一个需要一些时间才能完成的脚本。只有在它完成后(所以控制台上会显示"finished",来自于这行代码:
console.log('finished'
),下一个链接(“查看表格”)才会可点击(或取消隐藏等)。<h1>Search for a movie</h1>
<form action="results" method="GET">
<input type="text" placeholder="search term" name="search">
<input type="submit">
</form>
<p><a href="/run"> Run python </a></p>
<p><a href="/data"> See the table </a></p>
这里是app.js代码
var express = require("express")
var app = express()
var request = require("request")
var PythonShell = require('python-shell');
app.set("view engine", "ejs")
app.engine('html', require('ejs').renderFile);
var thelist =[]
app.get("/", function(req, res){
res.render("search")
})
var jsondata = ""
app.get("/results", function(req, res){
var query = req.query.search
var url = "http://www.omdbapi.com/?s=" + query + "&type=series&apikey=thewdb"
request(url, function(error, response, body){
if(!error && response.statusCode == 200){
var data = JSON.parse(body)
res.render("results", {data: data})
}
})
})
app.get('/data', function(req, res) {
//viewname can include or omit the filename extension
res.render(__dirname + '/well.html');
});
app.get("/show/:id", function (req, res) {
var id = req.params.id;
thelist.push(id)
console.log(thelist);
res.redirect('/')
});
app.get("/run", function(req, res) {
var pyshell = new PythonShell('script2.py');
pyshell.send(JSON.stringify(thelist))
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
jsondata += message
});
// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err){
throw err;
};
console.log('finished');
});
res.redirect('/')
thelist = []
});
app.listen(process.env.PORT, process.env.IP, function(){
console.log("Movie App has started!!!");
})
pyshell.end
函数完成后为其添加内联样式,这样可以吗?例如:var linkToEnable = document.querySelector(".link-to-enable); linkToEnable.style.display = "block";
(这只是一个例子 - 关键在于确定是否可以在预期的时刻添加内联样式:在所讨论的函数完成后)。 - UncaughtTypeError