开发者

redirect without page reload

开发者 https://www.devze.com 2023-04-06 00:50 出处:网络
I want to redirect error message to index page so i wrote the following code: $message=\"Bad answer, go back to page!\";

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.

  1. Use $.get or $.post to send data to PHP and get the returned data (this case : Bad answer, go back to page!)
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号