我试图让我的页面将我重定向到另一个页面,但 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, 洛杉矶, CA, 90045",}}]}&sourceCountry=USA&token=&f=pjson。
我猜我必须以某种方式解析它,但我不知道如何解析。
最佳答案
您必须使用 encodeURIComponent
对每个 URL 查询字符串参数进行编码(至少是动态的):
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';
关于javascript - 重定向奇怪格式的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25145202/