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 }
]

 

posted @ 2019-03-05 16:45  coderjim  阅读(3095)  评论(0编辑  收藏  举报

更多知识请点击——

www.7017online.xyz