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"

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.