将json与jquery一起使用Ajax不会返回任何内容

Aug*_*Ven 6 javascript ajax jquery json

我想学习如何将JSON与jQuery一起使用,所以我在其上进行了简单的视频教程.但是,在完成所有步骤并使用与视频中完全相同的代码之后,我仍然在console.log之后的控制台中看不到任何内容.我究竟做错了什么?

这是HTML页面:

<!DOCTYPE html>
<html>
<head>
    <title>Document</title>
</head>
<body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script>
    $.ajax({
      url: 'articles.json',
      dataType: 'json',
      type: 'get',
      cache: false,
      succes: function(data) {
        $(data.articles).each(function(index, value) {
          console.log("success");
        });
      }
    });
  </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我的JSON文件(articles.json),我试图使用这些文件:

{
    "articles": [
        {
            "id": 1,
            "name": "Article 1"
        },
        {
            "id": 2,
            "name": "Article 2"
        },
        {
            "id": 3,
            "name": "Article 3"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!

小智 -3

使用 $.getJSON

例子

$.getJSON( "articles.json", function( data ) {
 
  $.each( data.articles, function( key, val ) {
   console.log(val);
  });

});
Run Code Online (Sandbox Code Playgroud)

http://api.jquery.com/jquery.getjson/

  • 虽然这是一个不同的解决方案,但它并没有回答OP的问题,他拼错了成功。 (2认同)