Jump to content

Recommended Posts

Hi, thanks for the reply, With AJAX, will it interfere with my script?

 

Considering I haven't seen your script, nor do I know what it does, it's impossible to say.  The probable answer is no, but if you could post your code and explain what it does I, or someone else, may be able to give you a definite answer.

Link to comment
https://forums.phpfreaks.com/topic/132292-button-event/#findComment-688475
Share on other sites

You don't really need AJAX to do this.  You can do it with the appropriate javascript and style tags.

 

Consider something like this (the flush is key here):

<?php
?>
<html>
<head>
  <script language=JavaScript>
   function pleaseWait() {
    if (document.getElementById)
     document.getElementById('pleaseWait').style.visibility = 'hidden';
    else if (document.layers)
     document.pleaseWait.visibility = 'hidden';
    else
     document.all.pleaseWait.style.visibility = 'hidden';
   }
  </script>
</head>
<body onLoad=pleaseWait()>
  <span id=pleaseWait style="position:absolute;left:0;top:0;background-color:white;layer-background-color:white;height:100%;width:100%;">
   This might take a while, Please wait...
  </span>
<?  
flush();
sleep(10);
print "<br>Done sleeping<br>\n";
?>
</body>
</html>

 

Unless I misunderstood and you want to have your AJAX code generate a 'working' message while it is processing.  In that case, you'll want to check out xmlHttp.readyState and add a catch for it in your AJAX function.  Something like:

function ajax(target,value,handler) {
var xmlHttp;
try { xmlHttp=new XMLHttpRequest(); }
catch (e) {
  try { xmlHttp=new ActiveXObject('Msxml2.XMLHTTP'); }
  catch (e) {
   try { xmlHttp=new ActiveXObject('Microsoft.XMLHTTP'); }
   catch (e) {
    alert('Your browser does not support AJAX!');
    return false;
   }
  }
}
xmlHttp.onreadystatechange = function() {
  if(xmlHttp.readyState == 1 || xmlHttp.readyState == 2 || xmlHttp.readyState == 3)
   document.getElementById(target).innerHTML = 'Working, please wait...';
  else if(xmlHttp.readyState == 4)
   document.getElementById(target).innerHTML = xmlHttp.responseText;
}
xmlHttp.open('GET',handler+'?q='+value,true);
xmlHttp.send(null);
}

 

Steve

Link to comment
https://forums.phpfreaks.com/topic/132292-button-event/#findComment-688607
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.