php equivalent of UPDATEPANEL

Posted on 2007-11-25
Last Modified: 2012-06-27

I am trying to find a similar way to update a part of a page just like updatepanel works in Is there a ready function / component to use with php?

For example I want to have a DIV with some content and if someone clicks a button to refresh that DIV and add some contents retrieved from the database.

Question by:infodigger
LVL 28

Expert Comment

ID: 20347171
You would have to use AJAX for that
LVL 21

Accepted Solution

nizsmo earned 500 total points
ID: 20347805
As gamebits said, using ajax is a good way. To get you started here is a general function for ajax with PHP, but you have to change the values accordingly, code commented.
<script language="javascript" type="text/javascript">
function callAjax()
	var url = "test.php?user=myself"; // dummy, change to whatever your url is going to be...
function ajaxQuery(url)
	var page_request = false;
	// If  the browser is Mozilla, Safari etc
	if (window.XMLHttpRequest)
		page_request = new XMLHttpRequest();
	// If the Browser is Internet Explorer
	else if (window.ActiveXObject)
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		catch (e)
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
		  	catch (e){}
	else { return false; }'GET', url, true);
	// When request is Ready
		if (page_request.readyState == 4 && page_request.status==200)
			document.getElementById('results').innerHTML = page_request.responseXML;
<a href="#" onclick="callAjax();">click for Ajax</a><br><br>
<span id="results">This text is going to change after the ajax call...</span>

Open in new window


Expert Comment

ID: 35733301
i'm trying to implement this on wordpress site ->
 problem= pressing on the link doesn't change the url in the addressbar
any other solutions for this?
as i recall in asp the url also changed !!
and realy calling another address with diffrent SQL query,
while leaveing some element on the page intact and not going to the annoying white blink
i want to preserve the menu in place, while page data changes
only solution i came in mind right now is to use iframe for that but since i want the url address to change accordingly to links pressed - any ideas how to do that? web-layout for wordpress

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Row insertion failed. Array 5 46
Inserting data into database 10 34
Running a javascript project in WebStorm 2 24
Using toggleClass to resize Bootstrap columns 7 16
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question