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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM