samedi 23 janvier 2016

Passing data from Javascript to php with Laravel 5.1

I need to pass data from Jvascript to php using Laravel 5.1 So right now for example I have a blank page with input(name='q'). When I start typing it sends the query via Ajax data:{q: query} to php so then in php I am taking the value from q $query = e(Input::get('q', '')); (Laravel syntaxis) and I am processing the data and I have a respond from the php

return response()->json(array(
                    'data' => $data
        ));

So after Ajax is secceded. The ajax is taking the respond :

function(item, escape) {
                console.log(item);  }

And the data I am resiving is object

Object {url: "http://localhost:8000/well/3", name: "Welly", iso3_code: "NOR", class: "product"}

So far so good....

So by clicking a button I want to send this data via POST to some method.

After this all I need to take the "item" from js and save it to php variable so the via POST I can send this info to diffrened procces. So after the POST I will have the data for the other process.

I would have access to the object via the respond from the php 'data' => $data or from the js "item" .... But whatever I try I can not manage to do it.

Thank for helping me.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire