redirect without page reload
I want to redirect error message to index page so i wrote the following code:
$message="Bad answer, go back to page!";
header("location:index.php?message=".$message);
this code in process page, and i'm fetching data in index.php page like:
<?php
if(isset($_GET['message'])) {
$message=$_GET['message'];?>
开发者_开发百科 <?php echo $message; ?></iframe>
}
else { echo ""; }
?>
i tried to display message in iframe....but i couldn't succeed.
Your echoing the iFrame tags incompletely/incorrectly. Try this
<?php
if(isset($_GET['message'])) {
$message=$_GET['message'];
echo '<iframe>'.$message.'</iframe>';
}
else { echo ""; }
?>
When you are talking about DOM manipulation (without needing to refresh the page), you should know the best, most elegant way is to do that with Jquery / Ajax / PHP.
- Use $.get or $.post to send data to PHP and get the returned data (this case :
Bad answer, go back to page!
) - Get your
<div>
or<iframe>
element and load the returned data inside of your selected element with Jquery.
I don't know if you are willing to do some changes. If you are willing to do more changes, please drop a comment so I will give you a code example about it.
Some Information you must know;
$.get and / or $.post.
.load() to load returned data.
I hope this helps.
精彩评论