[英]How do I run a node.js function from an html page without using ajax/using express?
I have been having trouble with ajax, and I just want my html to pass a function when a button is passed, but that function is in a node.js file. 我在使用ajax时遇到了麻烦,我只希望我的html在传递按钮时传递一个函数,但是该函数位于node.js文件中。
How could I do this without AJAX, and if AJAX is required, could I be linked code? 没有AJAX怎么办?如果需要AJAX,可以链接代码吗?
Create index.js
file and attach it to your html (index.html)
file. 创建index.js
文件并将其附加到您的html (index.html)
文件。
Then in html
file if you are submitting form then pass onClick=functionName()
as attribute
in <form>
tag. 然后,如果要提交表单,则在html
文件中,然后在<form>
标记中将onClick=functionName()
作为attribute
传递。
In index.js
file, you can add functionName
function and that function works as your frontend
function. 在index.js
文件中,您可以添加functionName
函数,该函数用作您的frontend
函数。
Use axios
or inbuild request
to fetch data from that function via endpoint
. 使用axios
或inbuild request
通过endpoint
从该函数获取数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.