Solved

php equivalent of asp.net UPDATEPANEL

Posted on 2007-11-25
5
3,778 Views
Last Modified: 2012-06-27
Hello,

I am trying to find a similar way to update a part of a page just like updatepanel works in asp.net. 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.

Thanks,
John
0
Comment
Question by:infodigger
5 Comments
 
LVL 28

Expert Comment

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

Accepted Solution

by:
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...

	ajaxQuery(url);

}
 

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)

	{

		try

		{

			page_request = new ActiveXObject("Msxml2.XMLHTTP");

		}

		catch (e)

		{

			try

			{

				page_request = new ActiveXObject("Microsoft.XMLHTTP");

			}

		  	catch (e){}

		}

	}

	else { return false; }

  	

	page_request.open('GET', url, true);

	

	// When request is Ready

	page_request.onreadystatechange=function()

	{	

		if (page_request.readyState == 4 && page_request.status==200)

		{

			document.getElementById('results').innerHTML = page_request.responseXML;

		}

	}

	if(window.XMLHttpRequest)

	{

		page_request.send(null);

	}

	else

	{

		page_request.send();

	}

}

</script>
 

<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

0
 

Expert Comment

by:itzik_horesh
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now