0

Trying to access "responseJSON.original_total_price"

This is my code -

  const CartObject = theme.cart.getCart();
  console.log(CartObject.responseJSON.original_total_price)

Console View

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
NolWag
  • 21
  • 2
  • Welcome to Stack Overflow! Please take the [tour], have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Please post code, error messages, markup, etc. **as text**, not as a *picture* of text. Why: http://meta.stackoverflow.com/q/285551/157247 – T.J. Crowder Apr 09 '21 at 16:39
  • Duplicate of https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json – T.J. Crowder Apr 09 '21 at 16:39
  • this isn’t a duplicate of that question. this question is about accessing an object property in an ajax request variable, so it needs to be an async function with await. – Travis Wagner Apr 09 '21 at 19:01

2 Answers2

2

Making it an async function fixed it.

  const CartObject = await theme.cart.getCart();
  CartObject.total_price
NolWag
  • 21
  • 2
0

you need to use JSON.parse function on response e.g.

const responseParsed = JSON.parse(responseJSON.responseText)
Vulwsztyn
  • 2,140
  • 1
  • 12
  • 20