Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:04:14+00:00 2026-06-02T00:04:14+00:00

What i’m trying to do : i’m trying to do a shopping cart that

  • 0

What i’m trying to do : i’m trying to do a shopping cart that doesn’t reload the page each time you click on an item, but saves the selected items in the session.

so after the user clicks “add”, i’ll add the value to my session, then i’ll parse the session values in a json array and i’ll append the whole “product list” inside the cart..

The problem is that for some reason, it’s printing “Undefined” for data.dados[0].id_prod, while it should be printing the id of the product..

So, this is my controller:

//get the ajax ‘get’ ...
if (isset($_GET[‘id_prod’]) && !empty($_GET[‘id_prod’]) && isset($_GET[‘qnt’]) && !empty($_GET[‘qnt’])) {

  $ma = $this->loja_model->add_carrinho($_GET[‘id_prod’], $_GET[‘qnt’]);
  $carr = $this->loja_model->list_carrinho();

  if ( isset($carr) && !empty($carr) ) {
    $array[‘data’][‘dados’]=$carr[0];
    $array[‘data’][‘valor’]=$carr[1];
echo json_encode($array);
  }

  }

and it prints this json object after $.ajax was called:

{“data”:
  {“dados”:

  [
    {“id_prod”:“1”,“id_cat”:“4”,“produto”:“Barco Velho”,“descricao”:“Barco de madeira tipo canoa.”,“valor”:“100.00”,“custo”:“0”,“qnt”:49},
    {“id_prod”:“2”,“id_cat”:“1”,“produto”:“Fusca 68”,“descricao”:“Raridade. Impec?vel. Roda. Trio. Som. Estepe original.”,“valor”:“4000.00”,“custo”:“0”,“qnt”:11},
    {“id_prod”:“3”,“id_cat”:“2”,“produto”:“MonoMoto”,“descricao”:“Moto de uma roda s?”,“valor”:“18000.00”,“custo”:“0”,“qnt”:2}
  ],

  “valor”:84900}
}

This is my JS file :

       $.ajax({
  url:      ‘http://mdk-store.com/loja/index.php/lojavirtual/index’,
  data: data_prod,
  type:    ‘GET’,
  dataType:  ‘json’,
  async: true,
  success: function(data) {
    window.alert(data[0].id_prod);
  }


  });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:04:15+00:00Added an answer on June 2, 2026 at 12:04 am

    According to the JSON you should be using: data.data.dados[0].id_prod.

    In order to access the data in the way you expect your JSON would need to look like this:

    [
      {“id_prod”:“1”,“id_cat”:“4”,“produto”:“Barco Velho”,“descricao”:“Barco de madeira tipo canoa.”,“valor”:“100.00”,“custo”:“0”,“qnt”:49},
      {“id_prod”:“2”,“id_cat”:“1”,“produto”:“Fusca 68”,“descricao”:“Raridade. Impec?vel. Roda. Trio. Som. Estepe original.”,“valor”:“4000.00”,“custo”:“0”,“qnt”:11},
      {“id_prod”:“3”,“id_cat”:“2”,“produto”:“MonoMoto”,“descricao”:“Moto de uma roda s?”,“valor”:“18000.00”,“custo”:“0”,“qnt”:2}
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shopping cart which at this point in time sends items that
I'm trying to write a simple shopping cart Orchard module that will store items
I am trying to build a shopping cart site. When a user click add
i am just trying to crawl a single page start_urls = ['https://www.mileageplusshopping.com/shopping/b____alpha.htm'] but redirecting
I have a shopping cart script that I am trying to modify to support
So I am trying add an item to the shopping cart without clicking on
I'm trying to programmaticly add an item to the visitor's shopping cart. In the
I'd like to use Subsonic in a shopping cart application, but I'm trying to
I have a shopping cart checkout page and I'm trying to add a gift
I'm trying to show a list with shopping cart items in a row with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.