zoukankan      html  css  js  c++  java
  • Laravel

    一,前台模板文件  index.blade.php

    <!DOCTYPE html>

    <meta name="_token" content="{{ csrf_token() }}"/>                          <!-- 一定要加上这个,不然会报错  -->

    <script src="{{ asset('js/jquery-1.9.0.js') }}"></script>
    <body>
       <button onclick="go()">发送</button>
       <script>
        function go() {
            console.log(123)
            $.ajax({
                type: 'POST',
                url: 'article/add',
                data: { name:'武卡卡',age:'18' },
                dataType: 'json',
                headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function(data){
                  console.log(data);
                },
                error: function(xhr, type){
                  alert('Ajax error!')
                }
            });
        }
       </script>
    </body>
    <html>
     

    二,路由文件  web.php

    Route::post('article/add','ArticleController@add');
     

    三,控制器文件  ArticleController.php

    public function add(Request $req){
           return $req->all();
    }
     
     
  • 相关阅读:
    近似计算π(for循环)
    apache部署mo_python
    文件注释方法
    算法效率的度量
    ssh
    使用类名创建对象
    筛选网址
    常用django命令
    查看和关闭端口
    update脚本出错
  • 原文地址:https://www.cnblogs.com/500m/p/12807496.html
Copyright © 2011-2022 走看看