php - How can I use in javascript an object stored in my server? -


i declare in javascript 2 object stored in file.txt , use in code.

for example wrote in 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 can see, in example, items bans , rans stored in localstorage , used items counters. write same code new bans , rans stored in file.txt. think had done ajax don't know.

i think file.txt has wrote this:

bans: 1; //casual number rans: 5;  //casual number 

i hope understand, thank much.

it done ajax can done without

index.php

<?php     // read file.txt     // strip off comments     // value part of bans: 1 variable $bans     // value part of rans: 5 variable $rans  // testing $bans = 1; $rans = 5;  echo '<script>'; echo "var master_bans = $bans;"; echo "var master_rans = $rans;"; ?>  var counter = number(localstorage.getitem('rans')) || master_bans ; var counter1 = number(localstorage.getitem('bans')) || master_rans;  $('.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) ); }); </script> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -