0

I have a ajax fucntion that gets a json array from the php , 8 numbers formed like this ["0","0","0","0","0","0","0","1"] , As I get this in a var called data , data[0] and this kind doesen't work , how can I access this numbers ?

4
Contributors
3
Replies
29
Views
3 Years
Discussion Span
Last Post by Bachu
0

Try something like this...

<script>
$.ajax({
    dataType: "json",
    url: "getJson.php",
    success: function (data) {
       for (var index = 0; index < data.length; index++) {
          console.log(data[index]);
       }
    }
 });
</script>

You can see the results using your browser's dev tools, console.

1322d0546996dd704f1826485e46c7ab

0

Try the following example:

In index.php

 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function() {
    $.ajax({
    dataType: "json",
    url: "json.php",
    success: function (data) {
        for (var index = 0; index < data.length; index++) {
            alert(data[index]);
        }
    }
    });

});
</script>

In json.php

<?php
$array = array("0","1","2","3","4","5","6","7","8");
echo json_encode($array);
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.