conan318 Posted February 24, 2012 Share Posted February 24, 2012 <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> Quote Link to comment https://forums.phpfreaks.com/topic/257671-redirect-if-ajaxrequestresponsetext-1/ Share on other sites More sharing options...
requinix Posted February 24, 2012 Share Posted February 24, 2012 You're missing parentheses. As well as a description of your problem. It's nice to include that so we don't have to guess at what you want. Quote Link to comment https://forums.phpfreaks.com/topic/257671-redirect-if-ajaxrequestresponsetext-1/#findComment-1320688 Share on other sites More sharing options...
conan318 Posted February 24, 2012 Author Share Posted February 24, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257671-redirect-if-ajaxrequestresponsetext-1/#findComment-1320698 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.