我托管在Google App Engine上的URL服务返回JSON内容类型。
示例网址是this,它在浏览器中工作得很好。也通过http://jsonlint.com验证。
我使用下面的jQuery.ajax调用来获取响应。
jQuery.ajax({
type: "get",
url: "http://trim-pk.appspot.com/do?url=http://www.google.com",
dataType: "json",
success: function(response) {
alert(response);
}
});出了什么问题?为什么我得不到回应。它是空的。
我尝试过contentType: "application/json; charset=utf-8"和contentType: "application/json; charset=ISO-8859-1",但得到了500个。
以下是我的Firebug输出。

发布于 2012-02-27 20:48:16
您是否在AppEngine应用程序上配置了CORS?
发布于 2012-02-27 19:30:27
:和/是Url中的保留字符,具有特殊的含义。
要在Url参数中使用它们,必须对它们执行"Url encode"操作。浏览器会自动做到这一点。
在Javascript中,您必须通过encodeURIComponent()函数手动完成此操作。这应该能起到作用:
jQuery.ajax({
type: "get",
url: "http://trim-pk.appspot.com/do?url=" + encodeURIComponent("http://www.google.com"),
dataType: "json",
success: function(response) {
alert(response);
}
});更新:用encodeURIComponent替换了encodeURI。
发布于 2012-02-27 20:44:34
试一试
jQuery.ajax({
type: "get",
url: "http://trim-pk.appspot.com/do",
data: {
url: "http://www.google.com"
},
dataType: "json",
success: function(response) {
alert(response);
}
});https://stackoverflow.com/questions/9463956
复制相似问题