Jump to content

need ajax help


Recommended Posts

If you want to change the content on a portion of a page without reloading the entire page, you can set the innerHTML property of a div element.Here's an example that changes the innerHTML of a div when you click on a button. If you get the new content from an AJAX request, you can use the responseText property of that AJAX request as the text to display in that div:

<html><head><script>function update(){	// first, get a reference to that div element	var div = document.getElementById("UpdateDiv");	// next, set the innerHTML property of that div to display	// the new content.	div.innerHTML = "This is some new content.";	// If you had an AJAX request called xmlHTTP, you could set	// the innerHTML like this:	// div.innerHTML = xmlHTTP.responseText;	// Just hiding the button...no particular reason.	document.getElementById("ChangeButton").style.display = "none";}</script></head><body><div>This is some static content.</div><div id="UpdateDiv">This content will change</div><button id="ChangeButton" onclick="update();">Update</button></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...