lorewap3 Posted December 2, 2009 Share Posted December 2, 2009 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" Quote Link to comment https://forums.phpfreaks.com/topic/183778-dumping-json-object-works-but-still-cant-access-individual-elements/ Share on other sites More sharing options...
trq Posted December 3, 2009 Share Posted December 3, 2009 data.callback(response.data); Looks like it should simply be.... data.callback(response); to me. Quote Link to comment https://forums.phpfreaks.com/topic/183778-dumping-json-object-works-but-still-cant-access-individual-elements/#findComment-970212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.