Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to access json array elements when running nested ajax request
    primarykey
    data
    text
    <p>Does anyone know why I can't access the array keys in the generated json array. Basically, I am doing an ajax call, then on success, doing another one. Everything works fine and I am getting a full, healthy and valid json array return, but I cannot access the keys and values.</p> <p>My jQuery</p> <pre><code>$("#register-form").submit(function(e){ e.preventDefault(); var firstname = $('#regfirstname').val(); var surname = $('#regsurname').val(); var email = $('#regregemail').val(); var password = $('#regregpassword').val(); var band = $('#regband').val(); var website = $('#regwebsite').val(); var company = $('#regcompany').val(); var address = $('#regaddress').val(); var city = $('#regcity').val(); var state = $('#regstate').val(); var postcode = $('#regpostcode').val(); var country = $('#regcountry').val(); var phone = $('#regphone').val(); var age = $('#regage').val(); var subscribe = $('#regsubscribe').val(); $.ajax({ type : 'POST', url : '/ajax/register', data : 'firstname='+firstname+'&amp;surname='+surname+'&amp;email='+email+'&amp;password='+password+'&amp;band='+band+'&amp;website='+website+'&amp;company='+company+'&amp;street='+address+'&amp;city='+city+'&amp;state='+state+'&amp;postcode='+postcode+'&amp;country='+country+'&amp;phone='+phone+'&amp;age='+age+'&amp;subscribe='+subscribe, success : function(data){ // automatically log the user in $.ajax({ type : 'POST', url : '/ajax/login', data : 'email='+email+'&amp;password='+password, success : function(user){ alert(user.logged_in); }, datatype : 'json' }); }, datatype : 'json' }); }); </code></pre> <p>If I do <code>alert(user);</code> it alerts the entire json array. But as soon as i try and access a value within it, it returns undefined.</p> <p>Example json array:</p> <pre><code>{"logged_in":true,"firstname":"Joe","surname":"Bloggs","Full_name":"Joe Bloggs","email":"address@email.com","phone":"123456789","website":"www.site.com.au","age":"25","street":"1 Road Street","city":"Town","state":"BLA","postcode":"1234","country":"13","company":"Freedman Electronics","band":"Daysend","subscribe":"2","mics":0} </code></pre> <p>Any ideas? </p> <p>Is this even possible to do? (AJAX within AJAX I mean).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload