Jump to content

gamesmstr

Members
  • Posts

    140
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

gamesmstr's Achievements

Member

Member (2/5)

0

Reputation

  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?
×
×
  • 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.