[OpenLayers-Users] Error when parsing array with OpenLayers and Protocol.HTTP()

harko33 xhanrot at gmail.com
Fri Aug 22 11:35:33 PDT 2014


I'm trying to send a JSON file to my Node.js app via Protocol.HTTP. The file
is correctly sent, but I can't access to an array. Here is the relevant code
:

Client side

    (...)
        var vectorProtocol = new OpenLayers.Protocol.HTTP({
                        url: '/getcoords',
                        format: vectorFormat,
                        readWithPOST: true,
                        params: {
                            "code_company": "8501",
                            "data_company": [
                                {
                                    "origin": "2013P00109",
                                    "type": "LJ",
                                    "naf": "5610A",
                                },
                                {
                                    "origin": "2013P00110",
                                    "type": "FJ",
                                    "naf": "5481"
                                }
                            ]
                        }
                    });
    (...)

Server side, I try to build an array with only the "origin" field of my
array "data_company":

    function getCoords(params, callback) {
          var arrOrigin = params.data_company.map(function(d) {
             return d.origin;
          });
          (...)
    }

And I get this error :

> TypeError: Object [object Object] has no method "map"

It seems that my "data_company" is not recognized as an array but as an
object. I tried to JSON.parse(params) before but I get another error :

> SyntaxError: Unexpected token o

Anyway, I'm stuck. Do you have any clue to help me to solve this ?

Thanks



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Error-when-parsing-array-with-OpenLayers-and-Protocol-HTTP-tp5157904.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list