Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: New to ajax...

  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation New to ajax...

    Hi!
    I posted this on JavaScript but they didn't answer...
    Here's my code, It doesn't work but it needs to load a php file every 0.5 seconds and then put it in a div called content.
    I'm new to Ajax & JavaScript so it is a bunch of snippets merged together =/
    Code:
    function refresh()
    {
    	if (window.XMLHttpRequest)
    	  {// code for IE7+, Firefox, Chrome, Opera, Safari
    	  xmlhttp=new XMLHttpRequest();
    	  }
    	else
    	  {// code for IE6, IE5
    	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	xmlhttp.onreadystatechange=function()
    	  {
    	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    		document.getElementById("content").innerHTML=xmlhttp.responseText;
    		}
    	  }
    	xmlhttp.open('GET','chat.php,true');
    	xmlhttp.send();
    	setTimeout('refresh()', 500);

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    "They" are pretty much the same people that will answer you here.

    And the reason "they" didn't answer in your other thread is twofold:

    First, it has only been an hour since you opened that other thread (which I deleted, because crossposting violates forum rules). Since you don't pay any of the people here to do your work, you will have to wait until someone chooses to invest their free time in helping you.

    Second, "My code doesn't work and I don't know how to fix it" is a really bad incentive for anyone to help you. This is a place for professional exchange, which gives people willing to learn the opportunity to benefit from collective experience. It's not a free coding service.

  • #3
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by Darkfortune View Post
    It doesn't work but it needs to load a php file every 0.5 seconds and then put it in a div called content.
    1) Your problem could be with the code in chat.php

    2) you have a syntax error in
    xmlhttp.open('GET','chat.php,true');

    This tute might help you
    Last edited by bullant; 03-19-2011 at 07:08 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •