![]() ![]() I’d choose the object because objects can have named elements in javascript. You either need an array with two elements or an object with two elements. Normally, jsondecode () will return an object of \stdClass if the top level item in the JSON object is a dictionary or an indexed array if the JSON object is an array. Or getting data as arrays: $data = $_GET Īnyway, you are making the structure more complex than it needs to be because in javascript you are building an array of 2 objects: one object has lat property while the other has lng property, which is wasteful because you don’t need two array elements and two objects at the same time just for two values. The jsondecode () function takes a JSON-encoded string as its first parameter and parses it into a PHP variable. You are sending an array of objects, therefore, this should work: $data = $_GET In you sample code above you are trying to access a resultSet object, which doesn’t exist because you are not sending anything called resultSet. ![]() From javascript you are sending an array of objects but you want to access it like an array of arrays. Obviously there is more to the code that I’m not showing, but I think this is the relevant parts: GET 500 (Internal Server Error) Also to reiterate, This does work when I pass the PHP script literal values, so I know the script is working, I’m just not getting the sending and decoding part. I am sending this to my PHP script via ajax: resultSet.push( However, when I attempt to decode and use the values sent from Javascript/ajax… I’ve tried every possible combination of accessing the array of objects in the PHP script. The script works when I give PHP literal values.
0 Comments
Leave a Reply. |