搜尋

首頁  >  問答  >  主體

javascript - 新手求問ajax 取得數據

下載phpstudy搭建本機伺服器

#data.json如下

{
    name:"lvyuanyaun",
    age:"25"
}

hello.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
</head>
<body>
     <button id="btn">点击</button>
    <h5 id="text">....</h5>
    <script src="jq.js"></script>
    <script type="text/javascript">
        $("#btn").click(function() {
        $.ajax({
        type: "GET",
        url: "data.json",
        dataType: "json",
        success:function(data) {
           console.log(data)
        }
      });

   })
    </script>
</body>
</html>

network顯示data.json已被載入

##console.log(data)什麼都沒顯示

仅有的幸福仅有的幸福2807 天前451

全部回覆(1)我來回復

  • 迷茫

    迷茫2017-06-06 09:55:48

    把url那個參數改成有http的訪問位址試試

    回覆
    0
  • 取消回覆