jquery - Create and Post an Array[ Array[] ] to PHP - fputcsv() -


I am struggling with it ...

To create me posted on a php page The problem is a CSV file is this, I can not understand how to create a proper array and then post it to php to process it.

My php page has a function that repeats through the posted value and writes in CSV.

Function Output CSC ($ data) {$ Output = FOPN ("php: // output", "w"); Forex Currency ($ data as $ line) {fputcsv ($ output, $ line); } Fclose ($ output); }

I'm getting $ data via a post like this ...

  $ csvdata = $ _POST ['csvData'];  

Then the function is running ...

  Output CSV ($ csvData);  

When I post, I get an error Warning: Invalid argument for foreach ()

I know That's something to do with my origin in the original (posts from the page) page, or how am I sending it.

How should the array be formatted here (which works if I set it to php page then run the function)

  Output CSV (" Array ("name 3", "age 3", "city 3"), array ("name 2", "age 2", "city 2"), array ("name 1", "age 1", "city 1"), array ));  

Now, from my post-page, I am looping through some values ​​and a variable var newData = []; in which the array is array with the value as the value, when I print in the console, I get it ...

  array [aa [3] ], Array [3], array [3]]  

For me, it looks correct, but I'm most likely to lose this variable for processing correctly on the PRP page It's been a tough time.

I have tried several things, such as setting the input value variable, then posting.

  & lt; Input id = "csv" name = "csvdata []" /> $ ('# CSV') val (newData)  

I have jquery's $ Tried to use like post

  $ Post ("csvsave.php", {CsvData ': newData});  

Plus a bunch of other methods, however, I am wasting my time only to list them out as I think the above two methods should work and I remember a few simple ones. Can do.

Sometimes I get an incomplete result (like just one array) with PHP's print_r , I get all the values ​​in the CSV but in just one line, but this Always throws an error. I have been mentioned above, and sometimes writes the error on the CSV page.

I am very worried that any help or guidance will be highly appreciated. Thank you in advance!

Extra

If I do var_dump at the post value, then I get it

  Array (1) {[0] = & gt; String (59) "Name 1, Age 1, City 1, Name 2, Age 2, City 2, Name 3, Age 3, City 3"}  

Internal arrays


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -