0

I'm trying to pass an array from JavaScript to a PHP input. I want to pass my array as an array inside my input, not a string.

My array is this:

["0_1","0_2"]

And this is how I pass my array to my input:

$('#movefile_id').val(JSON.stringify(allfiledata));

Can I pass the array to the input file without making it a string?

3
  • 1
    you can't stackoverflow.com/questions/1696877/… Commented Nov 13, 2013 at 5:40
  • I see, I'll just have to make do with strings. Commented Nov 13, 2013 at 5:42
  • but you are referring to file input? Commented Nov 13, 2013 at 5:42

2 Answers 2

2

read this:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

you can convert your array to JSON

var arrayJavascript = JSON.stringify(["0_1","0_2"]);

and with PHP, read this:

http://php.net/manual/es/function.json-decode.php

$arrayPHP = json_decode($_POST["arrayJavascript"]);
1

Here is the step by step process given below

1- Covert the Javascript Array to JSON

2- Post that JSON string to PHP using jquery post or jquery get

This is possible through only using Ajax. Because javscript is a Client side language and PHP is a server side language.We can only connect both using Ajax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.