Results 1 to 3 of 3

Thread: [Ajax Beginner] ^^

  1. #1
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default [Ajax Beginner] ^^

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script language="javascript">
    	var XMLHttpRequestObject = false;
    	if(window.XMLHttpRequest){
    		XMLHttpRequestObject = new XMLHttpRequest();
    	}
    	else if(window.ActiveXObject){
    		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	
    	function getData(dataSource, divID){
    		if(XMLHttpRequestObject){
    			var obj = document.getElementById(divID);
    			XMLHttpRequestObject.open("GET", dataSource);
    			
    			XMLHttpRequestObject.onreadystatechange = function(){
    				if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){
    					obj.innerHTML = XMLHttpRequestObject.responseText;
    				}
    			}
    			XMLHttpRequestObject.send(null);
    		}
    	}
    </script>
    </head>
    <body>
    <h1>Fetching Data Using Ajax</h1>
    <form>
    	<input type="button" value="Display Message" onclick="getData('data.txt', 'targetDiv')" />
    </form>
    <div id="targetDiv"><p>The Fetched Data will go here</p></div>
    </body>
    </html>
    I can't trace the error
    data.txt : Ajax

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Is that all of your code, can you be a bit more specific about the error.

    I've tried running the code as posted but apart from the button there is no input field in the DIV to test.

  3. #3
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    yeah, it's work
    I put it in .html.. it must be .php

    thanks palz

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
  •