Javascript 从 Chrome 扩展程序连接到数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5769081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:46:25  来源:igfitidea点击:

Connecting to DB from a Chrome Extension?

javascriptmysqlgoogle-chrome

提问by Galz

I am building a chrome extension which will only be available for people within the company I work for. The extension needs input - which can be generated with a simple query to a shared MySQL DB server (to which all employees can access with read only permissions).

我正在构建一个 chrome 扩展程序,该扩展程序仅适用于我工作的公司内的人员。扩展需要输入 - 可以通过对共享 MySQL 数据库服务器(所有员工都可以使用只读权限访问)的简单查询生成。

The question is - since the extension is all client side (mainly Javascript) - what's the simplest way to access the DB and run the query? Do I have to create a php/java(/...) service which does that for the extension?

问题是 - 由于扩展都是客户端(主要是 Javascript) - 访问数据库并运行查询的最简单方法是什么?我是否必须为扩展创建一个 php/java(/...) 服务?

回答by sym3tri

You'll have to create an intermediary web app that will interface with the Database. Then you can make AJAX calls from the extension to your web app's API, which will in turn query the database and return results.

您必须创建一个与数据库交互的中间 Web 应用程序。然后,您可以从扩展程序向您的 Web 应用程序的 API 发出 AJAX 调用,后者将依次查询数据库并返回结果。

Chrome Extension → Web App API → MySQL

Chrome 扩展 → Web App API → MySQL

More info on Chrome AJAX API here

有关 Chrome AJAX API 的更多信息,请点击此处