javascript - $.getJSON data into array


i'm new in PHP and JAVASCRIPT.. i need to do a little script who takes the data from data.php with$.getJSON("data.php", function(json).. and push it into 2 arrays in the HTML file, to reuse them.

data.php produce this:


at now i do this, but it doesn't run and i don't know how to do.

<!DOCTYPE html>
$(document).ready(function() {
    $.getJSON("data.php", function(json) {
            $row1[] = json[0];
            $row2[]= json[1];           





thanks to all guys ;)




Your assignment syntax is wrong. You can't put[] at the end of a variable in Javascript.

$(document).ready(function() {
    $.getJSON("data.php", function(json) {
        var row1 = json[0];
        var row2 = json[1];
        // put code that uses row1 and row2 here

People are also looking for solutions to the problem: javascript - json_encode of object results in intended callback wrapped in quotes


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.