Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access returned json data of php objects
    primarykey
    data
    text
    <p>I have created a large data structure in php which I send back to a jQuery "post" request. The data arrives in the following format</p> <pre><code>"{\"event\":{\"id\":\"5\",\"title\":\"Test Event\",\"event_ref\":\"TEST\",\"approval\":\"na\",\ </code></pre> <p>The data is sent back as a double quoted string with the double quotes escaped. The url directory markers are also escaped. The above is just a small part of the string which is returned.</p> <ul> <li>If I alert(data) I get the string displayed in the alert box.</li> <li>If I alert(data[0]) I get a " displayed</li> <li>If I alert(data[event]) I get undefined displayed.</li> </ul> <p>Generally, I can not use either dot notation or array notation to access the data. I suspect I need to get rid of the outer enclosing double quotes and un-escape it. The data is an array, some of the items are simple values, some are objects and some are arrays of objects.</p> <p>How do I access the returned data? The structure will allways be the same although some of the objects will often be missing.</p> <p>The js code is:</p> <pre><code>// The login button $("#loginButton").click( function(){ var username = $('input#login-username').val(); var password = $('input#login-passwd').val(); alert("Login button clicked with username/password: "+username+" / "+password); $.post( $_interface, { option: 'login', userID: username, pwd: password }, function(response){ if (response) { // alert("Response = true"); $.post( $_interface, { option: 'superGlobalValues', target: 'session' }, function(data){ alert(data); } ); } else { alert("Response = false"); } } ); } ); </code></pre>
    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.
 

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