Ralat Laravel AJAX 500
phpcn_u1582
phpcn_u1582 2017-05-16 16:54:49
0
2
611

Mengikut kaedah di Internet, ia masih mendapat ralat 500.
Penghala:

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

Pengawal Badan Pengawal:

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

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

Templat:

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

Ia tidak saintifik~ Ada yang tidak kena dengannya! ! !

phpcn_u1582
phpcn_u1582

membalas semua(2)
曾经蜡笔没有小新

di mana Pengecualian Ralat,
di mana Pengecualian Ralat,
di mana Pengecualian Ralat.

给我你的怀抱

Tidak dapat memahami ˍ╰

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan