Laravel AJAX 500 error
phpcn_u1582
phpcn_u1582 2017-05-16 16:54:49
0
2
598

According to the method on the Internet, it still gets a 500 error.
router:

Route::get('/','Admin\BodyController@index');
Route::post('/ajax','Admin\BodyController@ajax');

ControllerBodyController:

    public function index()
    {
        return view('Admin.Bodyadd');
    }

    public function ajax()
    {
        if(Request::ajax()){
            return Response::json(Request::all());
        }
    }

template:

<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="csrf-token" content="{{ csrf_token() }}" />
    <title>Cate</title>
   <link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

    <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.js"></script>
    <script src="{{ asset('/jquery-1.11.3.min.js') }}"></script>
    <script>






        $(document).ready(function(){

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


           $('#ContentAdd').click(function(){




               $.ajax({

                   type:"post",
                   url:"{{url('/ajax')}}",
                   data:{

                       'title':$('input[name=title]').val(),
                       'content':$('textarea[name=content]').val(),
                   },
                   dataType: 'JSON',



                   success: function(data){
                       console.log(data);
                       $('#postdata').html(data);


                   }


               });



            });

        });


    </script>
</head>
<body>

  <p class="container">

       <h1>Add Body</h1>
       <hr>
      <form>
          <p class="form-group">
              <label>标题</label>
              <input type="text" class="form-control" name="title">
          </p>
          <p class="form-group">
              <label>内容</label>
              <textarea class="form-control" rows="3" name="content"></textarea>
          </p>
          <input type="hidden" name="_token" value="{{ csrf_token() }}">
          <button type="submit" class="btn btn-default" id="ContentAdd">提交</button>
      </form>
        <p id="postdata"></p>
  </p>

</body>
</html>

Unscientific~ What’s wrong! ! !

phpcn_u1582
phpcn_u1582

reply all(2)
曾经蜡笔没有小新

where is Error Exception,
where is Error Exception,
where is Error Exception.

给我你的怀抱

Can’t understand╯ˍ╰

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template