weixin_33682719 2016-12-01 05:13
浏览 131

Ajax请求期间发生500错误

I am trying to hit a post route in Laravel and it is giving a 500 error. I tried a different route and it works.. Please note that we have recently added ssl to the site.

the error message in Chrome Dev tools

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

The HTML code :-

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

jquery code :-

$('#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 code:-

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条回答 默认 最新

  • 喵-见缝插针 2017-03-20 14:00
    关注

    OThe reason of the error is naturally server side error due to reasons like syntax error or file inclusion related error or something like that. To debug this you need to know what is the error message produced by PHP and for that check the response of the ajax call.

    If nothing found that means the error reporting in your php is off. You can turn it on from php.ini file like this

    error_reporting  =  E_ALL
    display_errors = On
    

    or may be via coding also. Like as follow;

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

    or may be via .htaccess file like this;

    php_flag  display_errors        on
    php_value error_reporting       2039
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图