SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple ajax form not working not displaying updated ..

    Hi there,

    i am wanting to develop a ajax application a simple one i found using an ajax div refresh in a project i am currently working on but i have never done such a thing where i change the div of the submited content

    here is a copy of my ajax and html code

    Code:
    <script type="text/javascript">
    <!-- 
    //Browser Support Code
    function ajaxFunction(){
    	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('ajaxDiv');
    			ajaxDisplay.innerHTML = ajaxRequest.responseText;
    		}
    	}
    	var age = document.getElementById('per').value;
    	var wpm = document.getElementById('email').value;
    	var queryString = "?per=" + age + "&email=" + wpm;
    	ajaxRequest.open("POST", "testPost.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    </script>
    <body>
    <div id="ajaxDiv"><form method="post" action="" name="myForm">
    	<input type="text" name="per" id="per" />
        <input type="text" name="email" id="email" />
        <input type="submit" name="set" value="Send Info"onclick='ajaxFunction()' />
    </form>
    </div>
    My problem is why isnt the div ajaxDiv not displaying the content of test.php once the data has been submitted?

    can anyone help me with this please in what i am doing wrong so basically i am wanting to get the content of ajaxDiv to be updated with new content once the submit button has been pressed.

    But my ajax and html code doesnt want to do this for my php code i have this

    PHP Code:
    print_r($_POST); 
    Just so i can see what is being sent but i cant see anything and most of the time i get ajax errors or is it somthing wrong in the php code part?

    can anyone help me find out as i am keen to learn to use ajax in all of my web applications i develop.

    Thanks,William

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    You may wish to investigate the book called Bulletproof Ajax which also provides online all of the code examples and live demos.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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