dongyi6543 2013-09-12 11:43
浏览 19

隐藏页面在重新加载时已发送表单的事实

I have used a form to submit an image id to the another page. I have done this rather than r than via url because it makes the url cleaner. However, when the user now reloads, it asks if they want to submit the form again. The won't know they have submitted a form, as far as they are aware they have simply clicked an image and been brought to a page that displays that image bigger.

Is there any way around this, that saves the image id the hidden form field has sent via the form, yet refreshes the page for the user?

HTML

<a class="gallery-img span4 js-img-submit" href="#">
   <img src="img.jpg"/>
   <form action="/image" method="post">                                
     <input type="hidden" value="<?=$img['id']; ?>" name="image_id"/>
   </form>
</a>

JQUERY

$('.js-img-submit').click(function(){           
        $(this).find('form').submit();            
 })

PHP

$image_id = isset($_POST['image_id']) ? $_POST['image_id'] : false; 
  • 写回答

2条回答 默认 最新

  • dsdxlibt98300 2013-09-12 11:55
    关注

    Somehow the parameter needs to be send to the image page.

    • GET: You dont want that.
    • POST: You use that, but causes the refresh problem.
    • SESSION: Will be hidden, but cause troubles, when he opens multiple images, and then refreshing the first page.

    So, i would to the following:

    Use the hashtag, and load the image via javascript then. finally remove the hashtag:

    MainPage:

    <a class="gallery-img span4 js-img-submit" href="/image#<?=$img['id']; ?>">
       <img src="img.jpg"/>
    </a>
    

    ImagePage:

    <script language="javascript">
    $(document).ready(function(){
       var imgid = document.location.hash.slice(1);
       document.location.hash = ""; //Remove
       loadImage(imgid);
    })
    </script>
    

    loadImage then needs to be the required javascript function.

    The user might notice it for a split second. IF the user is not allowed to see, then your only way would be to use the PHP Session with seperate variables for every opened image-window.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀