Jump to content

Recommended Posts

<script language="javascript" type="text/javascript">

function updateq(){
  var ajaxRequest;  // The variable that makes Ajax possible!
  
  try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
  } catch (e){
    // Internet Explorer Browsers
    try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try{
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
        // Something went wrong
        alert("Your browser broke!");
        return false;
      }
    }
  }
  // Create a function that will receive data sent from the server
  ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
      var ajaxDisplay = document.getElementById('ajax');
     
      ajaxDisplay.innerHTML = ajaxRequest.responseText;
       if ajaxRequest.responseText == '1'{
      	window.location = 'chat.php'
      }
    }
  }
var queryString = "?update=queue";
  ajaxRequest.open("GET", "ajax-chat.php" + queryString , true);
  ajaxRequest.send(null); 

  

}

//-->

</script>

Link to comment
https://forums.phpfreaks.com/topic/257671-redirect-if-ajaxrequestresponsetext-1/
Share on other sites

is my go at using ajax so bare with me as get my head around it.

 

ok im new to world of ajax.

 

iam trying to make a small one on one help chat. if 2 users are in the chat anyone after that gets put into a queue.

when the admin end the chat  i have function which removes the other user from the chat and from queue table in my mysql database.

 

that part works fine.

 

i have a second function running on a javascript timer which updates queue.

so then  i am trying to redirect the user that is next in line depending on the response.

 

if response text == 1 redirect that user into the chat room.

 

ajax


<script language="javascript" type="text/javascript">

function updateq(){
  var ajaxRequest;  // The variable that makes Ajax possible!
  
  try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
  } catch (e){
    // Internet Explorer Browsers
    try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try{
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
        // Something went wrong
        alert("Your browser broke!");
        return false;
      }
    }
  }
  // Create a function that will receive data sent from the server
  ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
      var ajaxDisplay = document.getElementById('ajax');
      ajaxDisplay.innerHTML = ajaxRequest.responseText;
    }
    
       if(ajaxDisplay.innerHTML == "1"){ 

window.location.replace="chat.php"; 
exit; 


    }
  }
var queryString = "?update=queue";
  ajaxRequest.open("GET", "ajax-chat.php" + queryString , true);
  ajaxRequest.send(null); 

  

}


//-->
</script>

 

ajax-chat.php


if ($update=="queue"){

$result = mysql_query("SELECT * FROM  q"); 
$num_rows = mysql_num_rows($result);

if ($num_rows >2){
echo "Welcome ".$_SESSION['myusername']." there are ".$num_rows." people ahead of you in the queue";

}else{
echo "1";
}
}

 

 

let me know if you need more info

 

 

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.