How to correctly receive ajax's post data?

Posted 7 months ago by AlexanderKim

Here's ajax:

            $.upload = function(file) {
                let out = new FormData();
                out.append('file', file,;

                    method: 'POST',
                    url: '/summer-uploads',
                    //check laravel document:
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                    contentType: false,
                    cache: false,
                    processData: false,
                    dataType: 'JSON',
                    data: out,
                    success: function(url) {
                        $('#description').summernote('insertImage', url);
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error(textStatus + " " + errorThrown);


    public function summerUploads(Request $request)
        if ($request->ajax()) {
            $file = $request->input('file');

            return response()->json($file->path());

        return App::abort(404);

But i'm keep getting an error: "Call to a member function path() on null"

I guess, it's not getting the values from ajax's data? Because $file is null.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.