我必须调用一个javascript函数,该函数存在于nodejs app.post()
的html文件中。我必须在请求转到openup()
后立即致电app.post(/process-view-dnd-registration)
。这里的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();
。
答案 0 :(得分:0)
你不能这样做。有两种不同的方式:
/process-view-dnd-registration
路由。然后,您将处理响应并直接在您的页面中调用open_popup()
函数。类似的东西:
$("#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
});
});