JSON 不显示结果

json does not show the result

本文关键字:结果 显示 JSON      更新时间:2023-09-26

我有一个带有json请求的html文件。我无法让 json 显示结果。我犯了什么错误?

<p id="syno"></p>

这就是我应该看到结果的地方下面是那个的脚本

<script>
var apiUrl = 'http://words.bighugelabs.com/apisample.php?v=2&format=json';
$.ajax({
    url: apiURL,
    type: "GET",
    dataType: 'json'});
  success: function (response) {
            // The request succeeded
            console.log(response);
            parseWord(response);
        },
        error: function (xhr, status) {
            // The request failed
            console.log(status);
            showError();
        }
function parseWord(data) {
$('#syno').text(noun.ant);
}
</script>
函数

parseWord(data)永远不会被调用。如果您希望在 ajax 请求成功时运行parseWord(data),则必须执行以下操作:

$.ajax({
    url: apiURL,
    type: "GET",
    dataType: 'json',
    success: function parseWord(data) {
               $('#syno').text(data.noun.ant);
             }
});

我建议您查看有关此的文档