Laravel

laravel unserialize jquery form data

In this article, we learn how we can unserialize jquery form data in laravel, I will show you the step-by-step process so that you can understand how we can unserialize jquery data in laravel.

You can also learn how we can send csrf token with the ajax form submission.

Below is the ajax code in which I am taking the form data, using the form.serialize jquery method.

var data = $('#form').serialize();
                var url = '{{ route("store.terms") }}';
                axios({
                    method: 'POST',
                    url: url,
                    data: {
                    "_token": "{{ csrf_token() }}",
                    "data": data
                    }
                })

Below is my business logic is written in the controller when I am receiving the serialize data, sent by the jquery for, you can unserialize the data by using parse_str method.

/**
     * Store and update the terms
     * @return response 
     * @param  Request $request
     */
    public function storeUpdateTerms(Request $request)
    {   
        $unserializeData = [];
        parse_str($request->data,$unserializeData);
        dd($unserializeData);
    }

You can get a response like the below one.


Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button