java - Show a 'Please wait' alert on JSP when button is clicked. when the processing is complete on servlet, remove the alert -
my jsp page ondownload function calls servlet function below.i show alert 'please wait' when download button clicked.. when processing complete on servlet, close alert.
jsp code:
function ondownload(){ var dtype = 'download'; var url = "<%=strdownloadurltest%>"+"/downloadservlet?downloadtype="+dtype+"&pnumber="+'<%=custpno%>'; document.getelementbyid('downloadp').href = url; document.getelementbyid('downloadp').target='_blank'; }
processing @ servlet side, code:
byte content[]=null; try { getpdao getpdao= new getpdao(); for(int i=0;i<5;i++) { content=getpdao.getpfromeb( strpn); dateformat df = new simpledateformat("dd/mm/yy hh:mm:ss"); date dateobj = new date(); content=null; if(content==null) { thread.sleep(5000); } else { content=getpdao.getpfromeb( strpn); break; } }
finally have agreed use ajax (after not find other way round) response servlet below. i'm using ajax first time. have added below code in jsp , servlet code remains same before. please suggest if done correctly?
$.ajax({ type: 'post', url: '"<%=strdownloadurltest%>"+"/downloaddocservlet?downloadtype="+dtype+"&pnumber="+"<%=custpno%>"', data: { name: $('#dtype').val() }, beforesend:function(){ alert("please wait....."); // append loading image }, success:function(responsetext){ alert.close(); // successful request; data }, error:function(){ // failed request; give feedback user } });
Comments
Post a Comment