Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh instead of replace? 1

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
Hi guys,

I've just read this short tutorial about Ajax : I understand how easy it is to replace the content of a div by something else.

But how am I suppposed to do if, by the same Ajax technique, I just want to refresh a div whose content is supposed to change in accordance to the $_POST variable like in the example below?

As you can see, I'm trying to keep the HTML/PHP code structure as linear as possible to make it less confusing.

Code:
<?php

echo"

... some HTML ...

    <div id=\"update_zone\">
    
    ";
    
        if ($_POST["action"] == 1) {
        
        echo"
        page 1
        ";
        
        } else if ($_POST["action"] == 2) {
        
        echo"
        page 2
        ";    
        
        } else {
        
        }
    
    echo"
    
    </div>

... some HTML ...

";

?>

Thanks a lot to anyone who will help :)
 
If the PHP that you call via your AJAX POST request accepts an 'action' parameter, and returns different output accordingly, then all you'd need to do is pass in an ACTION parameter to get the required output.

Perhaps this post will help?


Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 

Thanks Dan :)

I've read the entry and I understand that you can transform data into POST vars from Javascript.

But, once the data is sent, how do I refresh the div named "update_zone"?

I see everywhere in other scripts that the div content is always replaced by the new content with innerHTML. But in my case, how do I do?

Thanks again :)
 
I must be missing something here, because as far as I can tell, all you want to use an AJAX call to replace the contents of a DIV, and the contents will depend upon a parameter passed into the AJAX request.

What am I missing?



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Is it that you perhaps need another PHP page to output the contents of div#update_zone that you include in your main page, e.g.

Code:
<?
	echo "... some HTML ...";
	echo "<div id=\"update_zone\">";
	include "divContents.php";
	echo "</div>";
	echo "... some HTML ...";
?>

and then you also call "divContents.php" in your AJAX request?



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi Dan :)

Thanks to you, I've finally understood the exact functionning of Ajax (I misunderstood the tutorial actually)

Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top