Hello! I have such a question. There is an array of the form:

arr[0][0]='name'; arr[0][1]='John'; arr[1][0]='surn'; arr[1][1]='Smith'; ... 

Those. in cell 0 the name of the field is stored, and in 1 its value. You need to pass it through AJAX . But when sent to the server, it says an array of undefined :

 Data Saved: Array ( [undefined] => undefined ) 

In the code (documentation) it looks like this:

 data: { name: "John", surn: "Smith", ... }, 

but I tried to convey directly:

 data: arr, 

Does anyone have any idea how to transfer such an array to the server? Thank you in advance.

    1 answer 1

    using the js join function, merge the array into a string according to the rule "key1 = value1, key2 = value2". And send a string to the server. Then, using the php function explode, first parse the key = value pairs, and then parse the resulting strings into keys and values.

    • And if among the parameters is "," ?? I also considered this option .. - alex_90
    • use any other character for the delimiter, for example "|". The main thing is to decide what could be in the array, but to pick up the separator should not be a problem, you can use a combination of characters, whatever - Barton
    • @Barton, "|" too busy :-( Although, wait, "$" seems to be free .. Everything found a way out .. But no, another free separator is required (for short arrays) .. In short, I went to look for a free character. (I found the problem myself: ))) - alex_90
    • four
      Idiocy, honestly. What did not please json ?? Apparently on the server side somehow incorrectly accept the data. Some characters to look for .. Horror) - Vitaly Kustov
    • one
      Download parser off. JSON'a I understand religion did not allow? In general, this is one of the many elementary solutions that can be nuggled - Zowie