How do you pass an array to the server side.

How do you pass an array to the server side.

INTONEINTONE Posts: 153Questions: 58Answers: 6
edited August 2015 in Editor

I have tried passing an an array to the server like this:

  o.data.business_contact.first_name = ["Saab", "Volvo", "BMW"]; 

I am getting an error notice: Array to string conversion. Is there a way to pass an array to the editor server side?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    The error you are getting suggests that the array is being sent to the server, but that the server is trying to set it in the database as a string. Would that be correct? What do you actually want to do with it?

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    i want to now process the array by looping over its entries.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited August 2015

    Unless you use the Join class, you would need to add some custom code to perform that loop and do whatever data processing you need.

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    Maybe this is the answer:

    use JSON.stringify(array) to encode your array in JavaScript, and then use $array=json_decode($_POST['jsondata']); in your PHP script to retrieve it.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    That would certainly be one option. Exactly how that is done will likely depend upon the exact implementation requirements!

    Allan

This discussion has been closed.