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

鍍金池/ 問答/HTML/ 如何獲得這個xml網(wǎng)頁的內(nèi)容?

如何獲得這個xml網(wǎng)頁的內(nèi)容?

http://2011.cma.gov.cn/qxxw/y...

我用jquery

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <script src="http://127.0.0.1/jquery-3.3.1.js"></script>
    <script>
function Ajax( ) {
     var url = 'http://2011.cma.gov.cn/qxxw/yw/index_228.xml';
      $.ajax(url, {
        type:"GET",
        dataType: 'jsonp',
        crossDomain: true,
            success:function(data){  
                alert(data);
            },
            error: function (e) {
                alert("error");
            }

      });
};
    </script>
  
    <input type="button" value="show content" onclick="Ajax();" />    

</body>
</html>

為何報錯,如何修改?

回答
編輯回答
忘了我

jsonp是需要服務(wù)端支持的,不是你想用就能用的

2017年1月25日 01:21
編輯回答
局外人

xml的內(nèi)容是沒法通過jsonp去拿的。jsonp的原理就是通過script把數(shù)據(jù)當做js引入進來

你可以考慮代理的方式,讓服務(wù)器去拿。

2017年3月5日 19:15
編輯回答
陌上花

dataType應(yīng)該是xml

代碼如下:

function Ajax( ) {
     var url = 'http://2011.cma.gov.cn/qxxw/yw/index_228.xml';
      $.ajax(url, {
        type:"GET",
        dataType: 'xml',
        crossDomain: true,
            success:function(data){  
                alert(data);
            },
            error: function (e) {
                alert("error");
            }

      });
};
2017年5月6日 12:53