javascript - Issue reading JSON file with AJAX request -


i have json file containing this:

{"users":["john","peter"]} 

i tried ajax request, , returns 2 names in users array, until working fine, however, when try edit json file, whether using php or manually, lets add 2 more names users array, this:

{"users":["john","peter","george","robert"]} 

i save json file, reload page , try ajax request once again, reason returns 2 names had prior adding 2 new ones. instead of returning

["john","peter","george","robert"] return ["john","peter"] 

any ideas why happening?

here ajax request:

var request = new xmlhttprequest();                         request.open("get","../file/data.json",true);  request.send();  request.onload = function(){      var data = json.parse(request.responsetext);      console.log(data);  }  

use jquery

<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script type="text/javascript">     $(function(){         $.getjson('../file/data.json',function(data){             console.log(data);         }).error(function(){             console.log('error');         });     }); </script> 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -