简体   繁体   English

将 JavaScript function 的值插入 SQL 服务器数据库

[英]Insert the value of a JavaScript function to an SQL Server database

Is it possible to add a JavaScript variable in an SQL Server database database (run an SQL query or stored procedure )?是否可以在 SQL 服务器数据库数据库中添加 JavaScript 变量(运行 SQL 查询或存储过程)? If so, how?如果是这样,怎么做?

With JavaScript only, no you cannot (unless you're using Node.js of course).仅使用 JavaScript,不,您不能(当然,除非您使用的是Node.js )。

The point is, you'll need some server-side code to interact with your database.关键是,您需要一些服务器端代码来与数据库交互。 You can use JavaScript in the browser to make an Ajax call to a server-side script ( PHP , Ruby , Python , ASP.NET , Node.js, etc.) that performs the interaction with the database. You can use JavaScript in the browser to make an Ajax call to a server-side script ( PHP , Ruby , Python , ASP.NET , Node.js, etc.) that performs the interaction with the database.

You can not access the database from JavaScript.您无法从 JavaScript 访问数据库。 You need to send your data to PHP, Ruby on Rails or ASP.NET or whatever you are using to implement the back end .您需要将数据发送到 PHP、 Ruby on RailsASP.NET或您用于实现后端的任何东西。

You can use Ajax to post to a web service of some sort (or any other server side script) to pass the JavaScript value.您可以使用 Ajax 发布到某种类型的 web 服务(或任何其他服务器端脚本)以传递 JavaScript 值。 The web service would access the database and save it... web 服务将访问数据库并将其保存...

You can easily access a database from JavaScript in Node.js .您可以从 Node.js 中的 JavaScript 轻松访问数据库

If you're doing it from the browser, you'll most definitely need some kind of mid-tier service which translates HTTP queries to the relevant database driver (you can write that in any language you want - PHP , JavaScript, ASP.NET , etc.). If you're doing it from the browser, you'll most definitely need some kind of mid-tier service which translates HTTP queries to the relevant database driver (you can write that in any language you want - PHP , JavaScript, ASP.NET , etc .)。

Set value of variable in the hidden field and get value of that field at server side when submit form and save it into the database....在隐藏字段中设置变量的值,并在提交表单时在服务器端获取该字段的值并将其保存到数据库中......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM