lundi 8 août 2016

Assign Ajax response to php variable

How do I assign my ajax response to a php variable, if it is even possible?

In my Laravel controller I have this method for that purpose:

public function editProductPost(Request $request)
{
    return response()->json([
        'sliderValue' => $request->get('value')
    ]);
}

And this is my Ajax:

    /**
     * Ajax Post
     */
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        type: 'post',
        contentType: "application/json",
        url: "",
        headers: {
            'X-Requested-With': 'XMLHttpRequest'
        },
        data: JSON.stringify({ 
            value: getSliderVal,
            productId : getPrId
        }),
        datatype: 'json',
        success: function(response) {
            // get response
            console.log(response.sliderValue)
        }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire