1

Hey, I've got a PHP file that that echo's an array that has been encoded with json_encode. This file is used by the jQuery ajax function to retrieve the array. I am unable to figure out how to use the array though, I have managed to alert variables but not arrays. Here is my code:

function sessionStatus(){
 $(document).ready(function(){
 $.ajax({type:"POST", url:scriptRoot+"sessionStatus.php", success:function(data){
 alert(data[0]);
 }
 });
 });
}
asked Nov 13, 2009 at 21:45

2 Answers 2

1
json_encode(array("data1","data2"));
$.getJSON("sessionStatus.php",function(data){
 alert(data[0]);
});

Should alert "data1"

answered Nov 13, 2009 at 21:51
Sign up to request clarification or add additional context in comments.

1 Comment

Thnx, didnt know I could do that ;)
0

you need to use

data.property as an object not like an array[property]

answered Nov 13, 2009 at 21:46

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.