javascript - How can I check if an API token is still valid -


i'm using token api, problem when token invalid (time live < 0) there's no way know it, go on , fill out form , when submit message "invalid token" annoyin. idea write script checks token's time live every 10sec example , if it's invalid can disable forms example or display box force user reload page. maybe guys have better ideas , please don't hesitate share.

you can in simple way, guess have "expiration time" set on server side token. can return time , have js function check value every x seconds or on every required action (open pop/form/etc).

probably when return token json can like

{     token:"1234567890",     expire: "1427484624" //timestamp in seconds, easier compare } 

then js function can simple as:

function isvalidtoken(token){     cts=math.floor(date.now() / 1000);     return (token>=cts); } 

and way can know easily.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -