[SOLVED] Jquery code is not working for some weird reason

Hey guys, trying to grab some information from a JSON file in my code, and ive tried many ways to get the information and im running out of ideas

The project is to build a store for mobile phones for my college.

$(document).ready(function () {

        $.ajax({
        url:"Store.json",
        data:{},
        dataType:"json",
        success : function(data){
            alert(JSON.stringify(data));
            var users = data.users;
            $("#data").html("");
            for(var  i = 0 ; i < users.length ; i++){

                var name = users[i].name;
                var Manufacturer = users[i].Manufacturer;
                var  Tank= users[i].Tank;
                var price = users[i].price;
                var maxwatts = users[i].maxwatts;
                var minimumohms = users[i].minimumohms;
                var picture = users[i].picture;
                var numberofbatteries = users[i].numberofbatteries;

                $("#data").append("<p>"+ name +","+ Manufacturer +","+ Tank +","+price+"</p>");
            }

        }



    });

});

and my JSON code is here

  "vapes": [{

      "name": "Reuleaux RX 200w",
  "Manufacturer": "Wismec",
  "Tank": "Kennedy RDA",
  "price": 420,
  "maxwatts": 200,
  "minimumohms": 0.1,
  "picture": "some shit goes here",
  "numberofbatteries": "3",
  "rating": 3
},
 {
  "name": "RDTA Box",
  "Manufacterer": "Wismec",
  "Tank": "Box RDTA",
  "price": 690,
  "max watts": 200,
  "minimum ohms": 0.1,
  "picture": "some shit goes here",
  "number of batteries": "2",
  "rating": 3
},
 {"name": "Alien",
  "Manufacterer": "Smok",
  "Tank": "Alien",
  "price": 314,
  "max watts": 200,
  "minimum ohms": 0.1,
  "picture": "some shit goes here",
  "number of batteries": "2",
  "rating": 1
}
  ]}

Thanks!

You're missing the first curly brace on your JSON, bad copy/paste?

Also, there are no users in the JSON file, so your users var will be null, and cause users.length to error.

i changed the for loop code to better fit my JSON file and i am still not displaying, the JSON is not missing a brace, it was a bad copy/paste.

   $.ajax({
            url:"Store.json",
            data:{},
            dataType:"json",
            success : function(data){
                alert(JSON.stringify(data));
                console.log("ITS WORKING");
                var vapes = data.vapes;
                $("#data").html("");
                for(var  i = 0 ; i <vapes.length ; i++){
                    var name = vapes[i].name;
                    var Manufacturer = vapes[i].Manufacturer;
                    var  Tank= vapes[i].Tank;
                    var price = vapes[i].price;
                    var maxwatts = vapes[i].maxwatts;
                    var minimumohms = vapes[i].minimumohms;
                    var picture = vapes[i].picture;
                    var numberofbatteries = vapes[i].numberofbatteries;

                    alert($("#data").append("<p>"+ name +","+ Manufacturer +","+ Tank +","+price+"</p>"));
                }

            }



        });

We can close this thread, i figured out the problem on my own

thanks for the help @snowBlind623

1 Like