-5
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
  <script src= "C:\Documents and Settings\vivek.aggarwal\My Documents\Downloads\jquery-1.11.1.js"></script>
  <script src="mydata.json"></script>
</head>
<body>
    <p id="demo"> ABC </p>
    <script>

    $.getJSON(mydata.json, function(data) {
        var output = data.login[0].one;
        document.getElementById("demo").innerHTML= output;
    });

    </script>
</body>

and this is my JSON file (mydata.json)

{
    "login": [
        {
            "one": "vivek"
        }
    ]
}
Phil
  • 157,677
  • 23
  • 242
  • 245
  • 1
    I'd start by quoting the URI, ie `$.getJSON('mydata.json', ...`. Of course, your console would have alerted you to this error, if you'd bothered to check it – Phil Jul 25 '14 at 05:46
  • 1
    Get rid of the duplicate jQuery script tags (`c:\documents....`) and change `$.getJSON('mydata.json'...)` Note the quotes. Please learn to use developer toolbar (press F12 in Chrome) – jasonscript Jul 25 '14 at 05:46
  • ... also, don't include `mydata.json` via a ` – Phil Jul 25 '14 at 05:47
  • and while you're using jQuery anyway... `$('#demo').html(data.login[0].one)` – Phil Jul 25 '14 at 05:49

2 Answers2

1

Try this method, it works for me.

$.ajax({
    url: 'mydata.json',
    dataType: 'json',
    success: function(result) {
       //Your code here, result is json obj
       $('#demo').html(result.login[0].one);
    },
    error: function() {
      // alert("error");
    }
});
Gaurav Gandhi
  • 3,041
  • 2
  • 27
  • 40
0

Try this it should work.

$.getJSON("mydata.json", function(data) { 
        var output = data.login[0].one;
        document.getElementById("demo").innerHTML= output;
});
Saddamhussain
  • 860
  • 5
  • 14