简体   繁体   English

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

[英]500 Internal Server Error - All Ajax calls, PHP

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).我在本地主机 (WAMP) 上开发的站点上的所有 AJAX 调用都收到相同的错误(500 内部服务器错误)。 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?也许我缺少 PHP 分机之类的? Any help would be much appreciated.任何帮助将非常感激。

Testing测试

I know the code works fine because i've navigated to the ajax action on my browser.我知道代码工作正常,因为我已经在浏览器上导航到 ajax 操作。 Also the code actually saves data to the database so I know it's finding the correct script and running it ok.此外,代码实际上将数据保存到数据库中,所以我知道它正在找到正确的脚本并正常运行。

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);
}

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.这将告诉您 PHP 代码中的问题所在。 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.conf or .htaccess files.如果这是一个语法错误(对于代码 500 来说似乎很可能),那么您需要在php.inihttpd.conf.htaccess文件中启用这些选项。 Alternatively, just take a look in your web server error log for the issue.或者,只需查看 web 服务器错误日志中的问题。

A 500 error is not a problem with your JS - it's server-side. 500 错误不是您的 JS 的问题 - 它是服务器端的。

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.然后这是通过我的错误处理程序运行的,它将 header 更改为 500。一旦我删除了未找到的插件,一切都很好。

Stupid mistake to make I suppose!我想是愚蠢的错误!

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

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