vendredi 24 mars 2017

How to get values from json reponse in laravel

Developing with laravel 5.4.

In the web file I have this route:

Route::get('cart/calcShipping/{shipping_method}', 'CartController@calcShipping');

I have a view with ajax call like this:

$.ajax({
            type: "GET",
            headers: { 'X-XSRF-TOKEN' : $_token },
            url: '' + '/1',
            success: function(data) {
                $('#shippingCost').val(data);
                $('#shippingCostText').text(data);
            }
        });

In my controller I have this function (I do some calculations that I did not include in the example. For testing I'm sending back hard coded values):

 public function calcShipping($shipping_method)
{
   return response()->json(['shipping_cost' => 100, 'order_total' => 200]);
}

The problem is I get [object Object] back on these lines, instead of the values:

$('#shippingCost').val(data);
$('#shippingCostText').text(data);

What am I doing wrong?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2nepg6R
via IFTTT

Aucun commentaire:

Enregistrer un commentaire