birdbrain24 Posted March 30, 2008 Share Posted March 30, 2008 I was wondering if there was anyway that i could only tell the ajax to update when the mysql changes. Heres my script, i was using setTimeout but it really is a cpu hog being played over and over! <?php ... if($xmlhttp == 'true'){ $update = $_POST['update']; if($update == 'true'){ echo '<strong>Username:</strong> ' . $users['username'] . ' <strong>Rank:</strong> ' . $users['rank'] . ' <strong>Cash:</strong> $' . number_format($users['cash']) . ' <strong>Vehicle:</strong> ' . $selected . ' <strong>Location:</strong> ' . $users['location'] . ' <strong>Reputation:</strong> ' . $users['reputation']; } } else { ?> <!DOCTYPE ... <head> <script language="javascript" type="text/javascript"> function UpdateUserbar(){ 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 do not support our technology!"); return false; } } } xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ document.getElementById('userbar').innerHTML = xmlhttp.responseText; setTimeout('UpdateUserbar();', 1); } } var params = "xmlhttp=" + "true" + "&" + "update=" + "true"; var url = "userbar.php"; xmlhttp.open("POST", url, false); xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send(params); } </script> </head> <body onload="UpdateUserbar();"> <div id="userbar"><!-- Userbar Here! --></div> </body> </html> <?php } ?> Quote Link to comment Share on other sites More sharing options...
XoSilenceoX Posted April 16, 2008 Share Posted April 16, 2008 The problem you would be running into here would be that you would be asking a MySQL & PHP based system to tell a Javascript what to do. This is the problem and cannot be done. at least as far as my knowledge goes. I think you can use Javascript to communicate with MySQL however since JS can be seen via view souce you expose yourself to hackers by releasing database security information. Quote Link to comment 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.