简体   繁体   English

如何在不使用Ajax /使用express的情况下从html页面运行node.js函数?

[英]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.

相关问题 如何使用node.js express框架将html表单的值从一页提交到另一页 - how to submit values of html form from one page to another using node.js express framework 在带有express的node.js中使用express.static(__ dirname)函数时,重定向到错误的html页面 - redirected to wrong html page when using express.static(__dirname) function in node.js with express 如何使用Node.js和Express以块的形式发送HTML? - How do I send HTML in chunks using Node.js and Express? 我们如何不使用Ajax将sql查询结果数据返回到node.js中的调用者函数? - how do we return sql query result data to caller function in node.js without using ajax? 如何使用ajax(获取方法)在html页面(客户端)中显示来自node.js服务器的json数据? - how to display json data from node.js server in html page(client) using ajax(Get Method)? 如何使用jade将数据从URL / API转换为node.js express中的表? - How do I convert data from a URL/API into a table in node.js express using jade? 使用AJAX Post和Node.js Express - Using AJAX Post and Node.js Express 使用 node.js 应用程序和快递,我如何将 function 传递给 ejs 页面而不立即运行 - With a node.js app and express, how can I pass a function to an ejs page without it running immediately 在 Node.js / Express 中,我如何“下载”页面并获取其 HTML? - In Node.js / Express, how do I “download” a page and gets its HTML? 从 html 页面使用 node.js 中的 Express 获取下拉值 - Get dropdown value using Express in node.js from html page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM