Jump to content

Basic Ajax DIV refresh not working


AKalair

Recommended Posts

Hi,

 

I'm trying to get this example working :

 

http://aleembawany.com/2005/09/01/ajax-instant-tutorial/

 

This is my code

<html>
<head>
<script type="text/javascript">

function loadurl(dest) { 

try { 
        // Moz supports XMLHttpRequest. IE uses ActiveX. 
        // browser detction is bad. object detection works for any browser 
        xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); 
} catch (e) { 
        // browser doesn't support ajax. handle however you want 
} 

// the xmlhttp object triggers an event everytime the status changes 
// triggered() function handles the events 
xmlhttp.onreadystatechange = triggered; 

// open takes in the HTTP method and url. 
xmlhttp.open("GET", dest); 

// send the request. if this is a POST request we would have 
// sent post variables: send("name=aleem&gender=male) 
// Moz is fine with just send(); but 
// IE expects a value here, hence we do send(null); 
xmlhttp.send(null); 
} 

function triggered() { 
// if the readyState code is 4 (Completed) 
// and http status is 200 (OK) we go ahead and get the responseText 
// other readyState codes: 
// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive 
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { 
        // xmlhttp.responseText object contains the response. 
        document.getElementById("output").innerHTML = xmlhttp.responseText; 
} 
} 
</script>
</head>

<body>



<div id="output" onClick="loadurl('test.html')" >click here to load my resume into this div <br> tests</div> 

</body> 

</html>

 

When I click on the text nothing happens though ?

 

Any ideas ?

 

Thanks !

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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