点击此网址会回复一些JSON:https://poloniex.com/public?command=returnTicker
尝试使用jQuery GET捕获该响应,如下所示:
$.get('https://poloniex.com/public?command=returnTicker', function(data) {
console.log(data);
});
失败。在Firebug中,我看到状态200 OK,但是红色,好像有404或500或其他一些错误代码,没有响应。有谁知道这里发生了什么以及为什么?
标题信息:
Response Headers
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection Keep-Alive
Content-Type application/json
Date Sun, 27 Apr 2014 18:02:42 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive timeout=5, max=100
Pragma no-cache
Server Apache/2.4.9 (Ubuntu)
Set-Cookie PHPSESSID=6e7d53687d98f8a492c8d7f8e07d9718; path=/; HttpOnly
Transfer-Encoding chunked
X-Powered-By PHP/5.5.10-1+deb.sury.org~precise+1
Request Headers
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Host poloniex.com
Origin null
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
答案 0 :(得分:0)
这是我最终做的事情,所以它可以帮助别人。事实证明这是一个相对简单的解决方法。您可以使用快速而脏的PHP文件作为AJAX请求的代理:
<?php
$file = file_get_contents($_GET['requrl']);
echo $file;
?>
现在不是直接点击url,而是调用代理并传入requrl参数:
$.get('proxy.php', { requrl: 'https://poloniex.com/public?command=returnTicker' }, function(data) {
console.log(data);
});