在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/人工智能  網(wǎng)絡(luò)安全/ JSONP跨域GET200但是還是報錯,直接進(jìn)入錯誤處理程序

JSONP跨域GET200但是還是報錯,直接進(jìn)入錯誤處理程序

代碼如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ajax請求json數(shù)據(jù)</title>
    <script type="text/javascript" src="jquery-3.3.1.js"></script>
</head>
<body>
    <button id="btn">ajax請求</button>

    <script type="text/javascript">

        $("#btn").click(function() {
            $.ajax({
               type : "get",
               async: false,
               url : "http://yunxtec.com/test/adlist.json",
               dataType: "jsonp",
               jsonp:"callback",
               success : function(data) {
                       alert(data[0][1]);
               },
               error : function(r) {
                       alert("fail");
               }
           });
        })
    </script>
</body>
</html>

報錯截圖如下:
圖片描述
GET狀態(tài)為200:
圖片描述
要獲取的是json網(wǎng)頁的數(shù)據(jù),網(wǎng)頁截圖如下:
圖片描述

請問問題出在哪里呢?如果要獲取adlist的index要怎么寫呢?可以的話貼一下代碼~~

問題困擾了我這個小白挺久的,求助??!

回答
編輯回答
懶洋洋
  1. 從報錯來看是語法錯誤,看起來不像是請求的問題而是這個json有問題。找個網(wǎng)站測一下這個json的格式吧。
  2. 獲取index? 數(shù)組方法map拿全部或者find拿1個
2017年6月1日 23:24
編輯回答
巫婆

jsonp時返回數(shù)據(jù)的格式不對,應(yīng)該是 callback(json) 而不是 json

2017年1月12日 09:18
編輯回答
情皺

你這數(shù)據(jù)是json,不是jsonp,如果服務(wù)器不歸你管,你就得自己想辦法弄個反向代理

2017年3月25日 22:48
編輯回答
青裙

廢話不多說,直接代碼。

$.ajax({
          type: "POST",
          url: '/baidu/map/initLink',
          dataType : "json",
          contentType: "application/json;charset=utf-8",
          success: function(data){
              
                  //console.log(data);
                for(var i=0;i<data.length;i++){
                    var polyline = new BMap.Polyline([
                    new BMap.Point(data[i].callLongitude,data[i].callLatitude),//起始點(diǎn)的經(jīng)緯度
                    new BMap.Point(data[i].calledLongitude,data[i].calledLatitude)], //終止點(diǎn)的經(jīng)緯度
                    {strokeColor:"green",//設(shè)置顏色 
                    strokeWeight:3, //寬度
                    strokeOpacity:0.5});//透明度
                     map.addOverlay(polyline);    
                }
          }
      });
      
2017年8月25日 15:20