Jump to content

gamesmstr

Members
  • Posts

    140
  • Joined

  • Last visited

Everything posted by gamesmstr

  1. Please See above. As I stated before, I am NOT interested in jQuery. The AJAX works fine and has for years. I'm not going to go recode my site after 6 years just to say I have jQuery. What I am adding is just a little perk and is more related to how to change the page title from inside an ajax called php file than the javascript itself.
  2. I have a game website. I want to be able to change the page title to alert players when a new news item affects them. I routinely use refreshing AJAX calls to refresh stats etc. These AJAX calls refer to a seperate php file. I have tried everything I can think of, but the solution eludes me. Here is the AJAX call (NO I am not interested in Jquery) function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; } function refresh_stats() { var xmlHttp3 = createXMLHttpRequest(); params = ''; xmlHttp3.open("POST","ajax/statsajax.php", true); xmlHttp3.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp3.onreadystatechange = function() { if(xmlHttp3.readyState == 4 && xmlHttp3.status == 200) { var brokenstring = xmlHttp3.responseText.split("-@[-"); if ( brokenstring[0] == 'stats' ) { document.getElementById("statbox").innerHTML = brokenstring[1]; } } } xmlHttp3.send(params); statupdate=setTimeout("refresh_stats()", 60000); } Here is a snippet of the PHP code that I am working with if ($timecheck1['id'] > $player['news']) { echo("<i><font color=red> * News! *</font></i>"); ?> <script type="text/javascript">document.title = "*News!* Immortalix";</script> <?php } else {?> <script type="text/javascript">document.title = "Immortalix";</script> <?php } I am assuming that it is not working because it is being called from a different document. Any suggestions would be most helpful.
  3. There is no need to pass session data back and forth. As session is stored in the active browser session and is not subject to post or get methods. I assign a session variable to a user's email address and then use that to query my database for their other information... this information is loaded in aver pave and is all based on that session variable.
  4. Separate each action under a condition statement and pass the variable condition as a variable through the ajax funtion... For example: if ($action = ''){ show the form } else if ($action = 'display'){show output}
  5. OK.. pull the inner html in as a variable, pass it to the php file, echo it 1st and then echo the new data.
  6. Sorry, been buried. When I can get some free time I'll help you.
  7. try putting your div inside the TD
  8. I'm not sure you can target a div by class... ID usually marks a specific item, class usually affects multiple items. Trying to update multiples at one time can't be done that way.
  9. I'm fairly certain it can be done and I'm not sure you need AJAX to do it. There seems to be some code missing here. What is the"next field" to be populated?
  10. I see one major problem right off the bat. Your requestActivities2 function isn't referencing any XMLHTTP request. See if this helps. function requestActivities2(url) { var http=getHTTPObject(); document.getElementById("divActivities").innerHTML = "Loading..."; http.open("GET", "" + url , true); http.onreadystatechange = handleHttpResponse; http.send(null); }
  11. I have my suspicions what is happening, but can you tell me what is actually happening visually? Are you getting any of your error messages?
  12. This is very possible.. I do it all the time. I have a game with a chat screen and in the side bar is a window with the player's statistics. I update the chat every 10 seconds and the stats every 60 seconds. Got some code for us to work with?
  13. test.php should read something like this: <html> <head> <script type="text/javascript"> function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; } function AJAX(action) { var xmlHttp = createXMLHttpRequest(); var input=document.getElementById("input").value; params = "action=" + action + "&input=" + input; xmlHttp.open("POST","test.php", true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { document.getElementById("dynamic_update").innerHTML = xmlHttp.responseText; refresh_stats(); } } xmlHttp.send(params); } </script> </head> <body> <?php $action=$_POST['action']; $input=$_POST['input']; if ($action=''){ ?> <div id="dynamic_update"></div> <textarea id="input"></textarea> <input type="button" value="Submit" onClick="javascript:AJAX('update');"> <?php }else if($action='update'){ echo"$input"; } ?> </body> </html> I'm a tad tipsy right now, but his should be pretty close.
  14. Try changing this: var mlength=strURL.getAttribute? parseInt(strURL.getAttribute("maxlength")) : "" if (strURL.getAttribute && strURL.value.length>mlength) strURL.value=strURL.value.substring(0,mlength) to this: var mlength=document.getElementById("myText").maxLength; if (strURL.length>mlength) strURL=strURL.substring(0,mlength);
  15. Not necessarily... You can put the Javascript in the <head> section of your page and have it call the same file it is in. Lets see if I can explain this in a non code way and see if it makes sense. Think of your browser and the server as 2 sides of a deep ravine and you want to build a cable car to cross it. First off we need to find a spot to make that crossing. That part is our target <div> </div>. Next we need to construct the cable mechanism that actually will enable transportation across. That part is our createXMLHttpRequest() function from my example in the thread I mentioned earlier. Next we need the cable car to actually transport things across. This would be the AJAX() function. This particular function is capable of sending our variables back and forth across the divide between server and client and getting the output of the designated PHP file and bringing the output back across to the client side at our <div> location. Does that help any?
  16. Yes you can, just pass them as an array. Use PHP to populate it with as few or as many as you like.
  17. Are you looking to limit it to a defined integer? Or are you trying to limit it to the maxlength of the textarea? Your textarea has a limit of 20 characters. I'm wondering where the 60 you are wanting to limit it to is coming from.
  18. I did a short summary of what does what in this thread. If it still confuses you, then feel free to ask. http://www.phpfreaks.com/forums/index.php/topic,309994.0.html
  19. AJAX doesn't call PHP functions. It opens PHP files and sends their output to a target html entity.
  20. what have you got so far that we can look at?
  21. Yeah, I see your problem.. Your solution is going to have to be php based. You can still pass the necessary variables via ajax post, but your security setup will have to be php pased.
  22. I see a few things. You are creating a function to open an ajax object (createObject) and never really using it. You are unnecessarily defining both xmlhttp and xmlhttp2 globally using createObject and then redefining them locally in the other functions. You are also mixing up your xmlhttp and xmlhttp2 variables in your function showWorkoutInfo. Try something like this: function createObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.'; } } var lastMessage = 0; var mTimer; function getChatContent(){ var xmlhttp = createObject(); xmlhttp.open("GET","http://" + location.host + "/lib/getMessage.php?chat=1",true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("chat_content").innerHTML=xmlhttp.responseText; //chat_div.innerHTML += '<p><div style="float:left;"><img src="' + avatar_node[0].firstChild.nodeValue + '" width="50"></div><div style="float:left;"><font class="chat_user">' + user_node[0].firstChild.nodeValue + '</font> <font class="chat_time">' + time_node[0].firstChild.nodeValue + '</font><br /><font class="chat_text">' + text_node[0].firstChild.nodeValue + '</font></div></p>'; document.getElementById("chat_content").scrollTop = document.getElementById("chat_content").scrollHeight; } } mTimer = setTimeout('getChatContent();',1000); xmlhttp.send(); } function showWorkoutInfo(str){ var xmlhttp2 = createObject(); xmlhttp2.open("GET","getInfo.php?id="+str,true); xmlHttp2.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp2.onreadystatechange=function() { if (xmlhttp2.readyState==4 && xmlhttp2.status==200) { document.getElementById("workoutRoutines").innerHTML=xmlhttp2.responseText; } } xmlhttp2.send(); }
  23. Now I'm confused. you are sending the data for the entire list and final results all at once? Can you post your code? It would help us understand exactly what it is you are doing.
  24. if the only time it is sent to the source is when you are calling it for the final time, then who cares?
  25. no, I'd make the random number in php, then store it in mysql. Then retrieve it and pass it to your final phase as a post variable, and verify that it matches the stored one.
×
×
  • 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.