我正在通过JSON请求在我的项目中实现Yahoo Placefinder。这似乎在Chrome / FF / Safari中运行良好,但是在Internet Explorer(所有版本)中,它无需下载它而不是发回请求。
Placefinder API的标准JSON resetset似乎有同样的问题 - http://where.yahooapis.com/geocode?location=San+Francisco,+CA&flags=J&appid=yourappid
这是我在项目中使用的代码的一部分。
$.ajax({
type: "GET",
dataType: "json",
cache: false,
url: "http://where.yahooapis.com/geocode?location="+ address+ ","+ postcode+ "+UK&flags=J&appid=yourappid",.....
为什么IE试图下载此文件?任何想法如何以与其他浏览器相同的方式发送请求?
提前致谢!
答案 0 :(得分:0)
当您在IE中使用JSON和Web服务时,最佳做法是首先对您的请求网址进行编码。 您可以使用该java脚本函数执行此操作:
sampleUrl = encodeURIComponent (地址+“,”+邮政编码+“+ UK& flags = J& appid = yourappid”);
然后在调用中使用 sampleUrl 参数:
$。AJAX({
输入:“GET”,
dataType:“json”,
cache:false,
url:“http://where.yahooapis.com/geocode?location=”+ sampleUrl
});
最诚挚的问候。