Laravel AJAX 500-Fehler
phpcn_u1582
phpcn_u1582 2017-05-16 16:54:49
0
2
612

Laut der Methode im Internet wird immer noch ein Fehler von 500 angezeigt.
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());
        }
    }

Vorlage:

<!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>

Es ist nicht wissenschaftlich~ Da stimmt etwas nicht! ! !

phpcn_u1582
phpcn_u1582

Antworte allen(2)
曾经蜡笔没有小新

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

给我你的怀抱

看不懂╯ˍ╰

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage