简体   繁体   English

在没有 POST 的情况下,将大数据集从 Javascript 保存到 mySQL 表?

[英]Save large data-set to mySQL table from Javascript without POST?

I have a large-ish amount of server-side data that I need to store in a mySQL table.我有大量的服务器端数据需要存储在 mySQL 表中。 [I'm a novice, working through the learning curve of javascript & php.] [我是新手,正在研究 javascript 和 php 的学习曲线。]

I'm thinking it's best to stringify the javascript array into a JSON object and send that to a PHP page to save to the database.我认为最好将 javascript 数组stringify化为 JSON 对象并将其发送到 PHP 页面以保存到数据库。 Once the data's in a PHP array, I know how* to get it into the database;一旦数据位于 PHP 数组中,我就知道如何* 将其放入数据库; I'm just not sure what's the best way to get it there .我只是不确定到达那里的最佳方式是什么

I can't POST ( like this example ) since the maximum length of a POST string is 2048 characters, and I have maybe 10-20kb of data .我不能POST像这个例子),因为POST字符串的最大长度是 2048 个字符,我可能有10-20kb 的数据

I'd rather not use AJAX or Node.js (like this example) for the sake of simplicity, and since this is a one-off (but both on my list to learn in the future!)为简单起见,我宁愿不使用AJAXNode.js (如本示例) ,而且因为这是一次性的(但两者都在我的列表中以供将来学习!)

Or, would it be best to create a temp text file to the server with javascript, and then call a PHP page to load & process the data?或者,最好使用 javascript 为服务器创建一个临时文本文件,然后调用 PHP 页面来加载和处理数据? (Although I can't find examples of how to do that without using POST .) (虽然我无法找到如何例子做到这一点,而无需使用POST )。

I understand the difference between server-side & client-side (thanks to this great explanation ) but the size limit of POST seems to be my issue?我理解服务器端和客户端之间的区别(感谢这个很好的解释)但是POST的大小限制似乎是我的问题?

*Also I'm a little unsure as to when/how it's necessary to encode data ( like with this deprecated mysql-real-escape-string example ) for storage with {json/posting/DB tables/text}. *此外,我有点不确定何时/如何对数据进行编码( 例如这个已弃用的mysql-real-escape-string示例)以使用 {json/posting/DB 表/文本} 进行存储。 In this case my data could contain 'single' & "double" quotes (but no foreign characters 国外 वर्ण), which [in my short experience] seem like the only times it will be an issue?在这种情况下,我的数据可能包含“单”和“双”引号(但没有外国字符 वर्ण),这 [以我的短暂经验] 似乎是唯一的问题?

Thanks!谢谢!

The problem is that Javascript is client side language while PHP is server side language.问题是 Javascript 是客户端语言,而 PHP 是服务器端语言。 This means that PHP cannot interact with the user without some HTML, CSS or JavaScript and visa-versa, JavaScript can't interact with server side files without some PHP.这意味着 PHP 无法在没有 HTML、CSS 或 JavaScript 的情况下与用户交互,反之亦然,如果没有 PHP,JavaScript 无法与服务器端文件交互。 Why is this?这是为什么? Since JavaScript is client side the user can edit it as they can see the code while with a PHP script it is all on the server and they are not able to see the code, only what it outputs/prints.由于 JavaScript 是客户端,用户可以编辑它,因为他们可以看到代码,而使用 PHP 脚本,它全部在服务器上,他们无法看到代码,只能看到它输出/打印的内容。 So in short you cannot do what you are asking without POST or GET and it is not possible to do this without a server side script such as a PHP script (Python is also very useful if you are thinking of learning more about web backends).因此,简而言之,如果没有 POST 或 GET,您将无法执行您所要求的操作,并且没有服务器端脚本(例如 PHP 脚本)也无法执行此操作(如果您正在考虑了解有关 Web 后端的更多信息,Python 也非常有用)。

There are numerous example of how to do this that you can find with a simple google search, here is a great example send data to MySQL with AJAX + jQuery + PHP您可以通过简单的谷歌搜索找到许多关于如何执行此操作的示例,这里有一个很好的示例,使用 AJAX + jQuery + PHP 将数据发送到 MySQL

Hope I could clarify your question.希望我能澄清你的问题。

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

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