Ajax请求期间出现500错误

时间:2016-12-01 05:13:57

标签: php jquery ajax laravel

我正试图在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']]);
    }

1 个答案:

答案 0 :(得分:0)

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
相关问题