0

I'm trying to get my page to redirect me to another page but the URL is in an odd format.
This is what it looks like:

url =http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/geocodeAddresses?addresses={"records":[{"attributes":{"OBJECTID":1,"SingleLine":"380 New York St., Redlands, CA, 92373",}},{"attributes":{"OBJECTID":2,"SingleLine":"1 World Way, Los Angeles, CA, 90045",}}]}&sourceCountry=USA&token=&f=pjson.

I'm guessing I have to parse it somehow but I do not know how.

lobuli
  • 109
  • 1
  • 9

1 Answers1

1

You have to encode each URL query string parameter using encodeURIComponent (al least the dynamic ones):

window.location.href = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/geocodeAddresses?addresses=' + encodeURIComponent('{"records":[{"attributes":{"OBJECTID":1,"SingleLine":"380 New York St., Redlands, CA, 92373",}},{"attributes":{"OBJECTID":2,"SingleLine":"1 World Way, Los Angeles, CA, 90045",}}]}') + '&sourceCountry=USA&token=&f=pjson';

further reading: Encode URL in JavaScript?

Community
  • 1
  • 1
Luizgrs
  • 4,765
  • 1
  • 22
  • 28