Javascript,为什么得到json错误? [英] Javascript, why get json err?

查看:78
本文介绍了Javascript,为什么得到json错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

checkTicker()
function checkTicker() {
  var dao = new XMLHttpRequest();

 //dao.open("GET", "https://api.fanyi.baidu.com/api/trans/vip/translate?q=hello&from=en&to=zh&appid=20171120000097357&salt=1435660288&sign=bcd4bc3fe3b120dddea66560f8533891",true);

  dao.open("GET", "https://poloniex.com/public?command=returnTicker", true);

  document.write("===111===") 
  dao.onreadystatechange = function() 
  {
        document.write("==222==") 
        document.write(dao.status) 

  }
  dao.send();
}





我的尝试:



如果我使用urlpoloniex.com来获取json,而不是问题,而dao.status是200;



但是如果我使用网址baidu获取json,什么也得不到,dao.status为0;



所有这2个网址都可以获得json in chrome。



为什么url baidu无法获取json,怎么办?



What I have tried:

if i use url "poloniex.com" to get json, not problem, and "dao.status" is 200;

but if i use url "baidu" to get json, get nothing , and "dao.status" is 0;

all of this 2 url can get json in chrome .

why url baidu can not get json, and how to do ?

推荐答案

这里没有人我会知道这个。我们不控制这些URL背后的代码。



您必须联系拥有这些网址的人,以了解您的请求中必须提交的内容,包括您的请求标题中必须包含的内容,以便服务器了解您的查询以及如何返回响应。
There is no way anyone here is going to know this. We don't control the code behind those URL's.

You have to contact the people who own those URL's to find out what has to be submitted in your request, including anything that has to be in the headers of your request, in order for the server to understand your query and how to return the response.


这篇关于Javascript,为什么得到json错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆