ajax - Laravel 与 AJAX

标签 ajax laravel

一行:-想要使用 ajax 将发布数据发送到 Controller 。

这个问题以前被问过很多次。

但我看不到问题的解决方案。

我的问题是:- “message”:“允许的内存大小 536870912 字节耗尽(尝试分配 262148096 字节)” 在 DEV TOOLS CHROME 的网络预览选项卡中。 我看到这个链接Allowed Memory size也有但是​​没有什么好处。 当只发布三个变量时,为什么会出现这个问题?

我的 Controller 代码

 public function store(Request $request)
{
    echo "<pre>";
    print_r($request);
    echo "</pre>";

}

Jquery 代码

$('body').on('click', '.submit_followers', function() {
    $('#pactId').val($(this).attr('data-pact'));
    $('#userId').val($(this).attr('data-user'));
    $('#followersForm').trigger('submit');
});
$(document).ready( function () {
   $.ajaxSetup({
      headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
  });
});
$('body').on('submit', '#followersForm', function(e) {
   e.preventDefault();
        $.ajax({
            type: 'POST',
            url: "{{route('pacts.addFollowers')}}",
            data: {
                '_token':$('input[name="_token"]').val(),
                'pactId': $('#pactId').val(),
                'userId': $('#userId').val()
            },
            dataType: 'json',
            success: function(res) {
                console.log(res);
            }
        });
    });

HTML 代码

<div class="col-2 d-flex align-items-center justify-content-center">
            <button class="btn btn-outline-violet btn-side-rounded submit_followers" data-user="{{Auth::id()}}" data-pact="{{$pact->id}}" type="button"><i class="fa fa-hand-spock-o"></i> Follow</button>
        </div>
{!! Form::open( [ 'method'=>'Post','id'=>'followersForm' ] ) !!}
@csrf
{!!Form::hidden( 'pactId',"",['id'=>'pactId'] )!!}
{!!Form::hidden( 'userId',"",['id'=>'userId'] )!!}

{!! Form::close() !!}

路由一个是资源,另一个是发布

Route::resource("/pactsFollowers","pactsFollowersController");
Route::post('pactsFollowersController/store', 'pactsFollowersController@store')->name('pacts.addFollowers');

最佳答案

试试这个

public function store(Request $request)
{
      dd($request);
}

关于ajax - Laravel 与 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59319973/

相关文章:

php - jQuery 警报不起作用

c# - 使用jquery在ajax的回调中调用ajax

javascript - 如何在 “onclick” 事件期间加载外部 php 文件?

laravel - 在 Laravel 中检查密码是否正确

mysql - 将 Laravel 上传到服务器后,我在路由页面上收到一条错误消息

php - 具有未大写 Laravel 关系的重复查询

javascript - ajax调用成功后如何获取下拉列表的当前值?

javascript - XMLHttpRequest.responseText 在调用 URL 时不写入值

php - Laravel 属于/有很多

Laravel 5 无效的自定义请求 - 不重定向