JSON解析问题JQuery,Ajax



我与JavaScript,jquery和ajax一起编写的测试程序有一个小问题。

这是我的代码:

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Index</title>
    <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
    <script src="script.js"></script>
</head>
<body>
<button> Push here </button>
</body>
</html>

JS

$(document).ready(function(){
   $('button').on('click',function(e){
       callPage()
  })
});

function callPage(){
    $.ajax({
        url: "http://events.restdesc.org/",
        type: "GET",
        dataType:'json',
        succes: function (response) {
            var data = response;
            console.log("hey");
            console.log(data.title);
        },
        error: function(error){
            console.log("the page was not loaded", error);
        },
    });
}

但是,如果我检查网络,我发现我得到了请求,但是我没有成功,因此控制台没有记录任何内容。这怎么可能?

使用.done()代替成功

function callPage(){
    $.ajax({
        url: "http://events.restdesc.org/",
        type: "GET",
        dataType:'json',

        error: function(error){
            console.log("the page was not loaded", error);
        },
    }).done(function(response) {
              var data = response;
            console.log("hey");
            console.log(data.title);
    });
}

最新更新