I would like to declare in javascript two object stored in a file.txt and use it in a code.
For example I wrote this in my index.php:
var counter = Number(localStorage.getItem('rans')) || 0;
var counter1 = Number(localStorage.getItem('bans')) || 0;
$('.redanswer').one('click', function(){
localStorage.setItem('rans', ++counter);
$( '.rtotal' ).text( counter + " concordano" );
$( '.btotal' ).text( counter1+ " non concordano");
$('.rgraphic').css("height", counter * 100 / (counter1+counter));
$('.bgraphic').css("height", counter1 * 100 / (counter1+counter) );
});
$('.blueanswer').one('click', function(){
localStorage.setItem('bans', ++counter1);
$( '.btotal' ).text( counter1 + " concordano" );
$( '.rtotal' ).text( counter + " non concordano");
$('.rgraphic').css("height", counter * 100 / (counter1+counter));
$('.bgraphic').css("height", counter1 * 100 / (counter1+counter) );
});
As you can see, in this example, the items bans and rans are stored in the localStorage and I used those items for the counters.
I would like to write exactly the same code but with the new bans and rans stored in my file.txt. I think this had to be done with AJAX but I don't know.
I think the file.txt has to be wrote like this:
bans: 1; //casual number
rans: 5; //casual number
I hope you understand, Thank you very much.