Ajax请求返回Error:200无数据的解决方法

Posted 一盏清茶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ajax请求返回Error:200无数据的解决方法相关的知识,希望对你有一定的参考价值。

先看代码

 1 $.ajax({
 2         type:"GET",
 3         url:"https://****/charts/data/genre2.json",
 4         dataType:"json",
 5         success:function(data){
 6             if(data.errorCode==0){
 7                 console.log("成功,无数据");
 8                 console.log(data);
 9             }else{
10                 console.log(data);
11                 createChart(data);
12             }
13         },
14         error:function(jqXHR){
15             console.log("Error: "+jqXHR.status);
16         }
17     });

报错现象:页面为空

解决方式:因为返回200表示请求成功,已返回网页;但是无数据,那么可以检查数据;

[
  {\'genre\':\'Sports\',\'sold\': 275 },
  { \'genre\': \'Strategy\', \'sold\': 115 },
  { \'genre\': \'Action\', \'sold\': 120 },
  { \'genre\': \'Shooter\', \'sold\': 350 },
  { \'genre\': \'Other\', \'sold\': 150 }
]

如上,这是要请求的数据,将json内单引号改为双引号再测试即可;

[
  {"genre":"Sports","sold": 275 },
  { "genre": "Strategy", "sold": 115 },
  { "genre": "Action", "sold": 120 },
  { "genre": "Shooter", "sold": 350 },
  { "genre": "Other", "sold": 150 }
]

 

以上是关于Ajax请求返回Error:200无数据的解决方法的主要内容,如果未能解决你的问题,请参考以下文章