I have this ajax code for getting json from Jobs.json file.
Jobs.json code is below.
Now I want to rewrite $.each function dynamically.Tha t is, it will write the json string as key and value instead of .append() .
Code:
$(document).ready(function(){ $('#btn2').click( callJobs ); }); function callJobs() { alert("getting results..."); $.getJSON('Jobs.json', function(JSON){ $('#result').empty(); $.each(JSON.jobs, function(i, JOB){ $('#result') .append(JOB.Job +'<br />') .append(JOB.Priority+'<br />') .append(JOB.DueDate+'<br />') .append(JOB.Iscompleted+'<hr />'); }); }); }
Code:
{ "jobs":[ { "Job":"Job1", "Priority":"Low", "DueDate":"11.03.2013", "Iscompleted":"No" }, { "Job":"Job2", "Priority":"High", "DueDate":"11.03.2013", "Iscompleted" : "No" }, { "Job":"Job3", "Priority":"Medium", "DueDate":"11.03.2013", "Iscompleted":"No" } ] }
Comment