Jump to content

Dumping JSON object works but still can't access individual elements


lorewap3

Recommended Posts

I can't figure out what in the world is wrong. I have an ajax call that sends the data to a callback function when it's successfully (which is has been every time).

 

Inside the callback function (data.callback points to updateList function), the dump of the object works fine (in blue font). I see everything perfectly returned. But if I try to access any element directly (in teal font), it says that data is undefined. I don't understand how the dump would work if data is undefined.

 

I beg of you guru gods, I am hopelessly lost in this and would appreciate any information at all. I don't know where to begin to troubleshoot something this weird.

 


Ajax call

$.ajax({

type: "post", // Request method: post, get

url: postUrl, // URL to request

data: data, // Form variables

dataType: "json", // Expected response type

success: function( response, status) {

// Response was a success

if (response.success === true) {

data.callback(response.data);

 

// Response contains errors

} else {

alert('Ajax call was successfully but response.success failed!');

}

 

},

error: function(response, status) {

alert('Error occurred in ajax call!');

}

});

 


Callback function

updateList: function(data){

var tableHeader;

 

// Clear table

sandbox.request({ request: 'clear',

module: this.module,

id: this.id+"Table"});

 

 

// Create Row

tableHeader  = "<tr>";

tableHeader += "<th><pre>"+dump(data)+"</pre></th>";

tableHeader += "<th>"+data[0].Inventory.name+"</th>";

tableHeader += "</tr>";

 

// Add table header

sandbox.request({ request:'append',

  module: this.module,

  id: this.id+"Table",

  html: tableHeader });

                }

 

 


Snippet of dump call:

    '0' ...

        'Inventory' ...

            'id' => "2"

            'name' => "7131 Gun Cleaner"

            'manufacturer' => "Grow Group"

            'product_number' => "0"

            'type' => "solvent"

            'alt_name' => "Gun Cleaner"

            'specific_gravity' => "0.81459999084472656250"

            'voc_lpg' => "6.76000022888183593750"

            'msds_date' => "2007-01-28"

            'solid_lpg' => "0.00000000000000000000"

            'metric' => "222"

            'comment' => "test"

            'created' ...

            'modified' => "2009-11-01 19:11:33"

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.