简体   繁体   中英

Update external json file value

I have an external file with a value 0. I need to be able to increase the value each time this file is accessed?

json file.

number = '[{"num" : 0}]'

How can I update the value of this external json file from js?

var mydata = JSON.parse(number);
alert(mydata[0].num);
//how add +1 to this value and update the external file?

since you have the file on the server side, so to update the number every time you access the file, you need a server side programming like PHP or python etc. Then you can use ajax get or post request to that file and on request that file php will increase the number.

The way you can send request to the file using jquery:

$.get("YOUR_JSON_FILE", function(data, status){
    // response and data you get from server
});

you can take a deep look on it in more details in the link below : Jquery Ajax Request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM