【发布时间】:2018-07-07 03:15:03
【问题描述】:
我必须从 nodejs app.post() 调用 html 文件中存在的 javascript 函数。一旦请求到达app.post(/process-view-dnd-registration),我必须立即致电openup()。此处的 html 文件包含要显示的弹出窗口的设计。我尝试使用popup.openup() 调用该函数。但它没有用。请在下面找到我的代码。
server.js
app.post('/process-view-dnd-registration',function(request,reply){
popup.openup();
var json_blob = ({
"header" : {
"event_const" : "CNST_PREFERENCE_REGISTRATION_EVENT"
},
"jsonblob" : {
"MobileNo":request.body.hidMobile,
"SubscriberPrefCategory":request.body.ServiceProvider,
"PreferenceDate": today,
"PreferenceStartTime":request.body.datetimepicker3,
"PreferenceEndTime":request.body.datetimepicker4
}
});
request.body = json_blob;
route.invoke(request,reply);
reply.write('<script>setTimeout(function () { window.location.href = "/view-dnd-registration.html"; }, 3000);</script>');
})
popup.html:
<html>
<head>
</head>
<body>
//contains the design for popup
<script>
function open_popup(){
alert("calling open_popup");
$("html, body").animate({ scrollTop: 0 }, "slow");
openpopup();
}
</script>
<script>
$("html, body").animate({ scrollTop: 0 }, "slow");
function openpopup()
{
alert("calling open popup function");
var id = '#dialog';
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(500);
$('#mask').fadeTo("slow",0.9);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
}
</script>
</body>
</html>
请帮我如何在节点js中调用函数openup();。
【问题讨论】:
-
你是从哪里调用 http-request 的?
-
如何将信息从客户端发送到端点
process-view-dnd-registration? -
我们正在通过表单操作发送信息。但建议不要使用ajax调用。
标签: javascript jquery html node.js