java - Newbie 'Can you do this with Dojo/Ajax' Question -
i have web page has function send initial request web service. after predefined time, user can send second request. after user sends first request, want web page countdown when user may send second request. after countdown, want db field updated automatically, indicating appropriate time has passed. when time has passed , db updated, i'd webpage updated show button allow user send second request.
after initial request, call javascript user-defined function "countdown()
" using in-built javascript function "settimeout("countdown()", 4000)
", number "4000
" resembles number of micro-seconds need passed fire function mentioned in first parameter.
in "countdown()
" function, write logic ajax call, updating database desired time of 4 seconds (for example) has passed & user can send second request.
also in same ajax call, can print out word (let word "yes
" example), can catch / fetch in "countdown()
" function definition, using "responsetext
" keyword of javascript's "xmlhttprequestobject
", in dummy variable "flag
".
now can write following in "countdown()
" function definition:-
function countdown() { document.getelementbyid("btn_second_req").style.display = 'none'; var flag = ''; // code prepare ajax call // ajax called, return fetched in variable "flag". if (xmlhttprequestobject.readystate == 4 && xmlhttprequestobject.status == 200) { flag = xmlhttprequestobject.responsetext; } if (flag == 'yes') { document.getelementbyid("btn_second_req").style.display = 'block'; } }
so default, second request firing html button hidden first time, & activated when "flag
" variable condition satisfied.
also since details of first call of user being kept in db, in second call, need check server validation there exists details first call, otherwise second request call not entertained.
these type of logic can implemented using javascript framework library (like jquery or prototype) or plain javascript only.
hope helps.
Comments
Post a Comment