i want load json when page loading. found 2 methods difference between following 2 methods read json.
<script type="text/javascript" src="assets/json/mainpage.json"></script> //code
another method
$.getjson("assets/json/mainpage.json")
you did not find 2 different methods.
the first version not how works.
you can load javascript object using object notation using script tag,
<script type="text/javascript" src="assets/json/mainpage.js"></script>
could contain
var myjsobject = { "key":"value" };
whereas second method call returns (static or generated) content like
{ "key":"value" }
for example
$.getjson("assets/json/mainpage.php");
would call server process do
header("content-type: application/json"); echo '{ "key":"value" }';
Comments
Post a Comment