Steve Bals
Steve Bals

Reputation: 1979

display json data to view laravel

my json responce is

0: {id:3, product_price:91, product_quantity:3, count_product:1}
1: {id:2, product_price:10, product_quantity:13, count_product:1}

my jquery

$.get('items/', {'id': itemIds}, function (obj) {

                                console.log(obj);
                                 $.each(obj, function(i, item) {
                                 // console.log(item);
                                      console.log(this.product_quantity);
                                    });
                                    //alert(ic);
                            });

my controller code

echo json_encode($ccoun);

here each not working any help

Upvotes: 1

Views: 109

Answers (1)

clod986
clod986

Reputation: 2647

Change your JS function to:

    $.get('items/', {'id': itemIds}, function (obj) {
        console.log(obj);
        $.each(obj, function(i, item) {
            // console.log(item);
            console.log(this.product_quantity);
        });
        //alert(ic);
    }, 'json');

The only thing I changed is the last json.

EXTRA: for some reason, my old server didn't support $.get();, so I had to switch to $.ajax();. This might also help you in fixing it.

Upvotes: 1

Related Questions