How can I access my .json file using separate javascript to html, using .getjson?

Store your json file on server and provide the url to the file using getJSON :).

Up vote 0 down vote favorite 1 share g+ share fb share tw.

Gud day... i'm trying to write a program in javascript that uses .json. I already wrote one that is when I run the program, it will create a tab dynamically, using jquery, from my json data. It's already a running program but my json data is in my javascript code.

What im really confused about is how to do it using a separate . Json file, . Js and .html.

Here is my running javascript code with my json in it function CreateTab(o) { var str = ''; for (var I = 0; I ' + oi. Title + ''; } str += ''; for (var I = 0; I ' + oi. Desc + ''; } return str; } $(document).

Ready(function() { var json1 = {"title": "tab 1", "desc":"This is tab 1"}, {"title": "tab 2", "desc":"This is tab 2"}, {"title": "tab 2", "desc":"This is tab 2"} ; $('#tabs'). Append(CreateTab(json1, "#tabs", true)); }); our instructor wanted us to use jQuery.getjson() only to get our . Json file.

He said that is what we are going to use if we are to connect soon to the server. I studied the sample from api.jquery.com/jQuery.getJSON/ and yes, it can display the Singular sensation Beady little eyes Little birds pitch by my doorstep but the problem is, I don't how to do it if I will use {"title": "tab 1", "desc":"This is tab 1"}, {"title": "tab 2", "desc":"This is tab 2"}, {"title": "tab 3", "desc":"This is tab 3"} and much more in arrays of objects or object arrays.... I am new in using json file with javascript... so I really need help. Thanks a lot.

Json tabs dynamic getjson link|improve this question asked Feb 16 '11 at 2:57jayAnn194110 82% accept rate.

I believe the following should work although I haven't tried it myself. You basically call getJSON and pass it the url to your json file on your server. Then in the return function you parse the data use the parseJSON method which will parse the data into an object which can be used by your CreateTab method.

Var myJsonObj; $. GetJSON("example.com/myjsonfile.json", function(data) { myJsonObj = jQuery. ParseJSON(data); $('#tabs').

Append(CreateTab(json1, "#tabs", true)); }).

Problem solved. Here's my javascript code: function CreateTab(o) { ...//the code is same as the question } $(document). Ready( function() { $.

GetJSON('tabfromjson. Json', function(data) { $('#tabs'). Append(CreateTab(data)); $('#tabs').tabs(); }); }); here's my 'tabfromjson.

Json' file { "title": "tab 1", "desc":"This is tab 1" }, { "title": "tab 2", "desc":"This is tab 2" }, { "title": "tab 3", "desc":"Thistab 3" } if you are going to run this code, it will display three tabs with tab title and description in tabfromjson.json. You can add tab by just adding the data in the . Json file.

Hope this helps for someone who is fresh and new to json, and to someone who want to know about this.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions