首页 > 解决方案 > ERR EMPTY RESPOSNE 在 wordpress 中的 ajax 删除请求

问题描述

我正在尝试删除带有 REST api 端点的帖子。evry 在本地运行良好。但在直播(000webhost 服务器)上,它给出的错误没有响应文本。

http://mylivesite/wp-json/university/v1/nclike net::ERR_EMPTY_RESPONSE

这是js代码:

$.ajax({
        beforeSend: (xhr) => {
            xhr.setRequestHeader('X-WP-Nonce', universityData.nonce);
        },
        url: universityData.root_url + '/wp-json/university/v1/nclike',
        type: 'DELETE',
        //dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
        data: {like: thisLikeBox.attr('data-likeid')},
    })
    .done((response) => {
        thisLikeBox.attr('data-exists', 'no');
        var likeCount = parseInt(thisLikeBox.find('.like-count').html(), 10);
        likeCount--;
        thisLikeBox.find('.like-count').html(likeCount);
        thisLikeBox.attr('data-likeid', '');
        console.log(response);
    })
    .fail((response) => {
        console.log(response);
    })
    .always(function() {
        console.log("complete");
    });

}

错误指向主 jQuery.js 的这一行:

// Do send the request (this may raise an exception)
                xhr.send( options.hasContent && options.data || null );

帮助!!:(

标签: jqueryajaxwordpresserror-handlingwordpress-rest-api

解决方案


推荐阅读