[英]How to call a javascript function inside html from node js app.post()?
I have to call a javascript function which is present in html file from a nodejs app.post()
. 我必须从nodejs
app.post()
调用html文件中存在的javascript函数。 I have to call openup()
as soon as the request goes to app.post(/process-view-dnd-registration)
. 请求转到
app.post(/process-view-dnd-registration)
我必须立即调用openup()
app.post(/process-view-dnd-registration)
。 The html file here contains the design for the popup that is to be displayed. 此处的html文件包含要显示的弹出窗口的设计。 I tried calling the function using
popup.openup()
. 我尝试使用
popup.openup()
调用该函数。 But it didn't work. 但这没有用。 Please find my code below.
请在下面找到我的代码。
server.js 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: 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>
Please help me how to call the function openup();
请帮我如何调用函数
openup();
in node js. 在节点js中。
You can't do this like that. 你不能那样做。 There are two different ways:
有两种不同的方式:
/process-view-dnd-registration
route. /process-view-dnd-registration
路由。 Then, you will handle the response and call the open_popup()
function directly in your page. open_popup()
函数。 Something like that: 像这样:
$("#formId").submit(function(e) {
e.preventDefault();
var formData = {
'test': $('input[name=test]').val()
// All your input values
};
$.ajax({
url: '/process-view-dnd-registration',
type: 'POST',
dataType: 'json',
data: formData
}).done(function(data) {
// Call your open_popup() function here
});
});
openPopup
, and then handle it in your template page to determine whether or not to display the popup. openPopup
,然后在模板页面中进行处理以确定是否显示弹出窗口。 It depends on how you use templates in your project.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.