【问题标题】:500 error during Ajax requestAjax 请求期间出现 500 错误
【发布时间】:2017-04-15 15:29:01
【问题描述】:

我正在尝试在 Laravel 中发送一条帖子路线,但它给出了 500 错误。我尝试了一条不同的路线,它有效.. 请注意,我们最近向网站添加了 ssl。

Chrome 开发工具中的错误信息

jquery.js:4 POST https://murgency.com/saveRequestInfo 500 (Internal Server Error)

HTML 代码:-

<div class="form-group text-right">
                        <a href="" type="button" class="btn-sm-arrowhead" id="dwnBrochure"
                           title="Download Brochure">Download Brochure</a>
                    </div>

jquery 代码:-

$('#dwnBrochure').click(function (e) {

        var text_name = $('#txt_name').val();
        var countryCode = $('#countryCode option:selected').text();
        var text_number = $('#txt_number').val();
        var text_email = $('#txt_email').val();
        var package = $('#packagetype').val();
        var type = "agingParents";
        var url = '/saveRequestInfo';

        var data = {
            name: text_name,
            email: text_email,
            countryCode: countryCode,
            phone: text_number,
            package: package,
            type: type
        };

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $.ajax({
            url: url,
            data: data,
            type: 'POST',
            datatype: 'JSON',
            success: function (response) {
                if (response.status === true) {
                    window.location = "https://murgency.com/home-health-plans/senior/brochure-success";
                }
                else {
                    alert('failure');
                }
            },
            error: function (response) {
            }
        });
        e.preventDefault();
    });

routes.php

Route::post('saveRequestInfo', 'ServicesController@saveRequestInfo');

ServicesController 代码:-

public function saveRequestInfo(Request $request)
    {

        $data = $request->input();

        $object = new ParseObject("MedicalRequest");
        $object->set('name', $data['name']);
        $object->set('email', $data['email']);
        $object->set('package', $data['package']);
        $object->set('phone', $data['countryCode'] . $data['phone']);
        $object->set('type', $data['type']);

        try
        {
            $object->save();
            $status = true;
        } catch (ParseException $ex)
        {
            $status = false;
        }

        $this->sendBrochureEmail($data['email'], $data['name']);

        return Response::json(['status' => $status, 'message' => $data['name']]);
    }

【问题讨论】:

  • 你检查过这个stackoverflow.com/questions/30154489/… 吗?
  • 检查你的 Laravel/服务器日志,了解 500 是由什么引起的。
  • 响应失败..我正在检查..我将在 5-10 分钟内确认..请坚持..
  • 嘿,您可以点击控制台中的网络选项卡,找到此网络请求并单击预览选项卡以查看确切的错误。您将看到与浏览器上显示的错误一样的错误。

标签: php jquery ajax laravel


【解决方案1】:

O错误的原因自然是由于语法错误文件包含相关错误等原因导致的服务器端错误。要调试它,您需要知道 PHP 产生的错误消息是什么,并检查 ajax 调用的响应。

如果没有找到,则意味着您的 php 中的错误报告已关闭。您可以像这样从 php.ini 文件中打开它

error_reporting  =  E_ALL
display_errors = On

或者也可以通过编码。如下所示;

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

或者可以通过像这样的.htaccess文件;

php_flag  display_errors        on
php_value error_reporting       2039

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    相关资源
    最近更新 更多