search

Home  >  Q&A  >  body text

javascript - Newbie asking about ajax to get data

Download phpstudy to build a local server

data.json is as follows

{
    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 shows that data.json has been loaded

console.log(data) shows nothing

仅有的幸福仅有的幸福2810 days ago458

reply all(1)I'll reply

  • 迷茫

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

    Try changing the url parameter to an access address with http

    reply
    0
  • Cancelreply