How to access local json file using ajax in html page using javascript?

Sangeetha Mani
Posted by Sangeetha Mani under JavaScript category on | Points: 40 | Views : 1354
As i have tried to acces local json file using ajax in html page using javascript?

but when i click on the button i could not get the updated json data on the textbox.

below mentioned the Html code with javascript and json file

<!Doctype html>

var xmlHttpRequest;

function GetTime()
//create XMLHttpRequest object
xmlHttpRequest = (window.XMLHttpRequest) ?
new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");

//If the browser doesn't support Ajax, exit now
if (xmlHttpRequest == null)

//Initiate the XMLHttpRequest object"GET", "Data.json", true);

//Setup the callback function
xmlHttpRequest.onreadystatechange = StateChange;

//Send the Ajax request to the server with the GET data
function StateChange()
if(xmlHttpRequest.readyState == 4)
document.getElementById('lblTime').value = xmlHttpRequest.responseText;


<form id="form1" runat="server">

<input type="text" id="lblTime">

<input type="button" id="btnGetTime" value="Get Time" onclick="GetTime();">



Data.json file



Please help me , i could not find it out what is my fault in this...

Comments or Responses

Login to post response