0

I am sending some data with ajax, and as a response i get multidimensional array.

        $.ajax({
            type: "POST",
            url: "/slideshow/list.php",
            data: imageId,
            success: function(data){
                imagesList = data;
                console.log(imagesList);
                curentImage = imagesList[0];
            }
        });

Response, data looks like this. This is what i get on console.log(imagesList): I am using php, and the response is provided like this <?php echo json_encode($data) ?>

[
   [1,487124,"<img src=\"http:\/\/example.com\/images\/1\/487124.jpg\" \/>","http:\/\/example.com\/photos\/salle-a-manger---mineral\/649518","Title 1"],
   [2,732924,"<img src=\"http:\/\/example.com\/images\/1\/732924.jpg\"\/>","http:\/\/example.com\/photos\/salle-a-manger---","Title 2"],
   [3,341649,"<img src=\"http:\/\/example.com\/images\/2\/341649.jpg\"\/>","http:\/\/example.com\/photos\/salle-a-manger---","Title 3"]
]

If i try to access the first array with imagesList[0] it only shows [

How can i access the first or second array, or values inside of them?

2 Answers 2

1

specify the dataType in ajax request

 $.ajax({
            type: "POST",
            url: "/slideshow/list.php",
            data: imageId,
            dataType:"json",
            success: function(data){
                 $.each(data,function(key,value){
                       console.log('key:'+key+", value:"+value);
                       //do your stuff 
                 });
            }
        });
Sign up to request clarification or add additional context in comments.

Comments

0

Use this

var obj = $.parseJSON(data);

1 Comment

can you please add more detail?

Your Answer

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.