Take the 2-minute tour ×

I am trying to send a javascript array to an external php page, but the only thing the php page is picking up is the fact that I am sending array, not the actual data within the array.

javascript -

var newArray = [1, 2, 3, 4, 5]; 

            type: 'POST',
            url: 'array.php', 
            data: {'something': newArray}, 
            success: function(){

External PHP Page -


I know this question has been asked before, but for some reason, this isn't working for me. I have spent the last couple days trying to figure this out as well. Can someone please point me in the right direction.

current output (from php page) - Array (thats all the page outputs)

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You should use var_dump in stead of echo.

Echo is only for strings, integers, floats and it will print 1 if a boolean is TRUE, and Array for an array.

share|improve this answer
thanks, i just changed that, I am now getting that 'something' is an undefined index, and the var_dump is resulting in NULL –  user1472224 Jul 2 '12 at 15:14
If you were getting a readout of Array when you echoed $_POST['something'] it means you had an array there not a NULL. You changed something. –  Mihai Stancu Jul 2 '12 at 15:21
you're right, i reverted back to past code and am now getting "array(0) { }"...?? –  user1472224 Jul 2 '12 at 15:27
Take the entire JavaScript array and put it in a text file see how much space that would take up. Next multiply the length of the key 'something' with the number of elements in the array 2388. Add that to the number of bytes the text file is occupying. And come back with the final value and tell us (you might be exceeding post_max_size) which would be 2M by default but may be 4 or 8 on your server. Also check what your current post max size is. –  Mihai Stancu Jul 2 '12 at 15:42
thanks for the advice so far, i really appreciate it, but would you happen to know of an efficient way to get my javascript array to a text file. Right now, I am using "console.log" to see my array and copying that to a text file, but it seems as though it will take some time with the amount of data that i have –  user1472224 Jul 2 '12 at 16:30

You could also use print_r() which is a little more readable.

share|improve this answer
Readability comes after. If you want readability install xdebug which prettyprints stack traces and makes var_dump look readable. –  Mihai Stancu Jul 2 '12 at 15:43

Y don't you convert array into string with some special character as separator and explode it into php?

share|improve this answer
jQuery handles that! –  Mihai Stancu Jul 2 '12 at 15:18
the real array i need this to work for has a size of 2388. Would this method work for an array of that size? –  user1472224 Jul 2 '12 at 15:22
Yes it should work. –  Mihai Stancu Jul 2 '12 at 15:23

Your Answer


