开发者

Offline mobile application - should i be able to read in a localally stored JSON file?

开发者 https://www.devze.com 2023-03-26 13:44 出处:网络
My question is similar to the one here Trying to parse JSON file with jQuery but i don\'t seem to be able to adapt it.

My question is similar to the one here Trying to parse JSON file with jQuery but i don't seem to be able to adapt it.

I want to create an offline mobile app mainly using HTML5, CSS and JavaScript/Jquery All the files in the app will be cashed I hope when I've it working

I had thought to created a JSON file containing some data about computer labs - eg open hours capasity that type of thing

 {  "name":"Boole basement",
"location":"Main Campus",
"staffed":"Yes"}

A开发者_StackOverflow社区nd then read in the localy stored JSON file - parse it or whatever and then display each object in a new div. Initially I was just trying to get the data into one div. heck if I could get the contents of the JSON file to display I'd be delighted!

My HTML file

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>test</title>
<script src="jquery-1.6.2.min.js"></script>
<script>
/* <![CDATA[ */
$(document).ready(function(){
var test =" ";
var filename = "test.json";

$.getJSON(filename, function(json){
    $.each(json.labs, function(i, lab){
        test = lab.name;
        test+=" "+lab.location;
            $('#space').append(test);
            alert("Hi");


        });
   });
});

/* ]]> */
</script>
</head>
<body>

  <h2>available labs:</h2>
  <div id="space">some text</div>

</body>
</html>

PS Is what I've discribed even possible...


What you have described is entirely possible, yes. But your code needs work:

For example, your selector for space is incorrect (it's an ID in your mark-up, but you're using a class selector in your jQuery code).

(EDIT OK, I see you've edited your example code now).

0

精彩评论

暂无评论...
验证码 换一张
取 消