Php and javascript code to modify a csv file entries

血红的双手。 提交于 2019-12-11 22:46:30

问题


I try to describe my complete situation...

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.

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?

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

Practical examples are welcome.


回答1:


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.

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.

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.

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

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

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



来源:https://stackoverflow.com/questions/23106637/php-and-javascript-code-to-modify-a-csv-file-entries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!