简体   繁体   English

Ajax请求返回的响应为空

[英]Ajax Request returns with an empty response

I've got the follow situation: 我有以下情况:

On my local server I made this call 在我的本地服务器上,我拨打了电话

File: history.js 文件:history.js

$(document).ready(function() {
    $('button[data-pid]').click(function() {
        $.ajax({
            cache: false,
            data: JSON.stringify({ pch_id: $(this).data('pid') }),
            dataType: 'json',
            type: 'POST',
            url: REPAIR_BROKEN_BANNER_URL
        }).done(function(data) {

            $('#fix-broken-banner-text').text(data.message);

            if (!data.error) {
                $('#fix-broken-banner-modal').on('hidden.bs.modal', function() {
                    window.location.href = window.location.href;
                });
            }

            $('#fix-broken-banner-modal').modal('show');

        }).fail(function() {
            $('#fix-broken-banner-text').text(REPAIR_BROKEN_ERR_GENERIC);
            $('#fix-broken-banner-modal').modal('show');
        });
    });
});

Page inclusion 页面包含

<script type="text/javascript" src="/js/history.js"></script>
<script type="text/javascript">
    var REPAIR_BROKEN_BANNER_URL = '/admin/banners/repair-broken-banner/';
    var REPAIR_BROKEN_ERR_GENERIC = 'Unable to perform the action';
</script>

The server responds always with a JSON, still it happened an error. 服务器始终以JSON响应,但仍然发生错误。

The issue is on the production server. 问题出在生产服务器上。 (Production server is a virtual server with Debian). (生产服务器是带有Debian的虚拟服务器)。 When the ajax call the action, it gets always a blank response, with the follow headers: 当ajax调用该动作时,它总是得到一个空白响应,带有以下标头:

Request URL: http://debug.xxxxxxx.xxx/admin/banners/repair-broken-banner/ 要求网址: http : //debug.xxxxxxx.xxx/admin/banners/repair-broken-banner/

Request Headers CAUTION: Provisional headers are shown. 请求标头警告:显示了临时标头。

  • Accept:application/json, text/javascript, / ; 接受:application / json,text / javascript, / q=0.01 Q = 0.01
  • Content-Type:application/x-www-form-urlencoded; 内容类型:应用/ X WWW的窗体-urlencoded; charset=UTF-8 字符集= UTF-8
  • Origin: http://debug.xxxxxxx.xxx 来源: http//debug.xxxxxxx.xxx
  • Referer: http://debug.xxxxxxx.xxx/admin/banners/history-list 引荐来源: http//debug.xxxxxxx.xxx/admin/banners/history-list
  • User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 用户代理:Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 537.36
  • (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36 (KHTML,例如Gecko)Chrome / 32.0.1700.107 Safari / 537.36
  • X-Requested-With:XMLHttpRequest X-要求 - 由于:XMLHttpRequest的

Form Data 表格数据

  • pch_id:697f1eaa2fc691a9a7d22d315f7ed8c966febe8ec2c57c1c7a867897f6431dfb8b596ef9dd8f2394c875c638496f7ec9 pch_id:697f1eaa2fc691a9a7d22d315f7ed8c966febe8ec2c57c1c7a867897f6431dfb8b596ef9dd8f2394c875c638496f7ec9

I thought it could be a php error, but If I write a message and die at the first script call, the page remains blank. 我以为这可能是php错误,但是如果我写一条消息而在第一个脚本调用中死了,该页面将保持空白。 In the apache access logs there's no trace of the call. 在apache访问日志中,没有该呼叫的踪迹。 I've tried this call in firefox and it doesn't appear into the XHR tab, as though the call it's not performed. 我已经在firefox中尝试过此调用,但它并未出现在XHR选项卡中,好像未执行该调用一样。

EDIT: Javascript part is complete 编辑: Javascript部分已完成

I suppose you are using Adblock plus. 我想您正在使用Adblock plus。 It has nothing to do with the Javascript, and more to do with the URL itself. 它与Javascript无关,而与URL本身有关。

You have the word banners in the URL. 您在URL中有横幅词。 Request URL: http://debug.xxxxxxx.xxx/admin/ banners /repair-broken-banner/ 要求网址: http : //debug.xxxxxxx.xxx/admin/ 横幅 / repair-broken-banner /

Disable Adblock plus for your site, and it should work flawlessly. 为您的网站禁用Adblock plus,它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM