0

As per my scenario i would like to have response data which is getting as responseText by posing below code in jQuery.

var account_id = jQuery('input[name=account_id]').val();
console.log('Account Id is :: ' + account_id);

var recordData = $.getJSON("http://localhost/vtigercrm/index.php?module=Inventory&action=GetAccount&record=" + account_id, function(data) {
    recordData = data;
}); 
console.log(recordData);

This is the console output which i have seen in browser console.

enter image description here

In the browser console i can see that there is a data at responseText. How can i get that responseText data.

When i try to access by using

recordData.responseText

I got data as undefined.

Can anyone help me to access responseText?

Thanks & Regards,

Jaccs
  • 882
  • 2
  • 9
  • 28
  • Have you tried consoling out recordData.responseText within getJSON's function call? – MCMXCII Jan 04 '17 at 17:56
  • See also this async reference question: http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron – Rory McCrossan Jan 04 '17 at 17:58
  • @MCMXCII, I tried vice versa no use. – Jaccs Jan 04 '17 at 18:14
  • @RoryMcCrossan I do understand, but little doubt while applying. Can you give me any idea on how to make it possible on my scenario? – Jaccs Jan 04 '17 at 18:15
  • Basically you can only work with the `data` returned from your AJAX request within the scope of the `$.getJSON` method. – Rory McCrossan Jan 04 '17 at 18:38
  • @RoryMcCrossan, K.. i'm unable to use the synchronous/asynchronous callbacks to work with inside function data. Meaning that i'm getting the data inside the function, where as when i try to access it after the $.getJSON method i got undefined as a result. Help me to write the callback, like how should i get the data which is inside the function to outside. – Jaccs Jan 04 '17 at 18:48
  • That's my point - you can't. All you can do is call a function from within the callback to pass the data around as required. – Rory McCrossan Jan 04 '17 at 18:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/132331/discussion-between-jaccs-and-rory-mccrossan). – Jaccs Jan 04 '17 at 18:53
  • Please try to help me using chat room! – Jaccs Jan 04 '17 at 18:58

0 Answers0