500 内部服务器错误 - 所有 Ajax 调用,PHP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10065898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:19:01  来源:igfitidea点击:

500 Internal Server Error - All Ajax calls, PHP

phpajaxinternal

提问by user1065700

Issue

问题

I'm receiving the same error (500 Internal Server error) for all AJAX calls on a site I'm developing on my localhost (WAMP). I'm beginning to think that it might be the way my server is set up. Maybe I'm missing a PHP extension or something? Any help would be much appreciated.

我在本地主机 (WAMP) 上开发的站点上的所有 AJAX 调用都收到相同的错误(500 内部服务器错误)。我开始认为这可能是我的服务器的设置方式。也许我错过了一个 PHP 扩展或什么?任何帮助将非常感激。

Testing

测试

I know the code works fine because i've navigated to the ajax action on my browser. Also the code actually saves data to the database so I know it's finding the correct script and running it ok.

我知道代码运行良好,因为我已经导航到浏览器上的 ajax 操作。此外,代码实际上将数据保存到数据库中,因此我知道它正在查找正确的脚本并正常运行。

Code

代码

I've simplified the code to make testing easier.

我已经简化了代码以使测试更容易。

JS

JS

    $.ajax({type: 'GET',
        url: '/cms/performances/deleteperformance',
        data: 'id=' + id,
        dataType: 'json',
        success: function(result)
        {
            switch(result)
            {
                case 1:
                    //Refresh the page
                    location.reload();
                    break;
                case 0:
                    alert('error');
                    break;
                case 2:
                    alert('Incorrect call');
                    break;
                default:
                    alert('default');
                    break;
            }
        },
        error: function(xhr, ajaxOptions, thrownError)
        {
            var httpCode = xhr.status;
            alert(httpCode + ': ' + thrownError);
        }
    });

PHP

PHP

public function deleteperformanceAction()
{
    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);
    echo json_encode(1);
}

回答by Cal

Add this code at the top of your PHP:

将此代码添加到 PHP 的顶部:

ini_set('display_errors', 1); 
error_reporting(E_ALL);

That will show you what the problem is in your PHP code. If it's a syntax error (seems quite likely for a code 500), then you'll need to either enable these options in your php.ini, httpd.confor .htaccessfiles. Alternatively, just take a look in your web server error log for the issue.

这将显示您的 PHP 代码中的问题所在。如果是语法错误(对于代码 500 来说似乎很可能),那么您需要在php.ini,httpd.conf.htaccess文件中启用这些选项。或者,只需查看您的 Web 服务器错误日志中的问题。

A 500 error is not a problem with your JS - it's server-side.

500 错误不是你的 JS 的问题——它是服务器端的。

回答by user1065700

I've finally got to the bottom of this. In fact there was nothing wrong with the code. However, I did have a plugin that wasn't being found during bootstrapping. This was then being run through my error handler which was changing the header to a 500. Once I'd removed the unfound plugin everything was fine.

我终于明白了这一点。事实上,代码没有任何问题。但是,我确实有一个在引导过程中没有找到的插件。然后通过我的错误处理程序运行它,将标题更改为 500。一旦我删除了未找到的插件,一切都很好。

Stupid mistake to make I suppose!

愚蠢的错误,我想!