Reputation: 241
I am having trouble what to do with the array response of the ajax $.post request:
$.post(
'../php/adminindex.php',
{'functions': 'userdetail', 'userId': $('#selViewUserId').val()},
function(data) {
//var response = jQuery.parseJSON(data);
//alert(typeof(data));
alert(data);
}
);
the alert(data)
returns:
<pre class='xdebug-var-dump' dir='ltr'>
<b>array</b> <i>(size=1)</i>
0 <font color='#888a85'>=></font>
<b>array</b> <i>(size=4)</i>
'user_id' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'ADMIN'</font> <i>(length=5)</i>
'user_last' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'Admin'</font> <i>(length=5)</i>
'user_first' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'Test'</font> <i>(length=4)</i>
'user_type' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'5'</font> <i>(length=1)</i>
The commented 2 lines does not have any response and I can't figure out what is the problem.
I wanted to get the values inside data but data[0]['user_id']
and data[0]
does not return the desired output.
How can I get those data out for use?
Upvotes: 0
Views: 186
Reputation: 13128
In relation to your comment, you can access your data by doing the following:
var user_id = data[0].user_id;
Upvotes: 1
Reputation: 841
from your comment, it looks like you are receiving an array. Try accessing user id with
data[0].user_id
Upvotes: 2