php和javascript代码修改csv文件条目 [英] Php and javascript code to modify a csv file entries

查看:138
本文介绍了php和javascript代码修改csv文件条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试描述我的完整情况...

I try to describe my complete situation...

我使用php函数读取一个csv文件。我开发了一个php类,表示文件的一个条目。所以,我有一个php数组,其中包含我所有的条目。当我读取文件的所有条目,我使用一个php函数将它们可视化到表中。对于表,我使用 jQuery tableSorter

I read a csv file using php function. I developed a php class that represent an entry of the file. So, I have a php array that contains all my entries. When I read all entries of the file, I use a php function to visualize these into a table. For the table I use jQuery tableSorter.

现在,用户可以编辑此表的某些行这我写了一些javascript函数)。
此时,我需要保存(在csv文件中)每个修改的表行。有没有一个简单的方法来做到这一点?

Now, the user can edit some rows of this table (for this I wrote some javascript functions). At this point I need to save (on the csv file) every modified table rows. Is there a simple way to make this?

需要修改php数组吗?是否可能通过javascript代码修改php变量?
对不起,但我是关于这个的新的。

Need I to modify the php array? Is possibile to modify a php variable by javascript code? Sorry but I'm new about this.

欢迎实用的例子。

推荐答案

不,你不是修改PHP数组。有几种方法来处理您的请求。您可以使用表格中的输入字段发出POST请求,并将更改保存到CSV文件。

No, you're not modifying the PHP Array. There are several ways to handle your request. You could use the input fields in your table to make a POST request and save the changes to your CSV file.

JavaScript-ish方法可能是一个AJAX请求,它会在每个字段更改时触发。您的服务器/ PHP代码接受该请求,并只写该字段的数据。

The more Javascript-ish way could be an AJAX Request which is fired on change of each field. Your Server / PHP-Code is accepting that request and writes only the data of that field.

在这两种情况下,您都应该知道如何处理PHP中的POST请求/表单。通过POST提交表单生成一个新的PHP数组,可以访问$ _POST。

In both cases you should know how to handle POST requests / forms in PHP. Submitting a form by POST generates a new PHP array, accessible as $_POST.

实际示例取决于预期的行为。使用表单将在提交时重新加载页面。使用AJAX不。但是如果你是新的Javascript,AJAX(XMLHTTPRequest,如果你想读一些文档)的使用是有点棘手的

Practical examples are depending on the expected behavior. Using forms will reload the page on submitting. Using AJAX not. But the usage of AJAX (XMLHTTPRequest if you want to read some documentation) is a little tricky if you're new to Javascript

链接XMLHTTPRequest(AJAX) http://www.w3schools.com/xml/xml_http.asp

Link about XMLHTTPRequest (AJAX) http://www.w3schools.com/xml/xml_http.asp

关于表单处理的链接: http://www.w3schools.com/ php / php_forms.asp

Link about Form handling: http://www.w3schools.com/php/php_forms.asp

这篇关于php和javascript代码修改csv文件条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆