iframe标签实现form表单提交(如文件上传下载)不刷新

本文介绍了一种使用隐藏iframe实现表单提交时页面无刷新的技术,并进一步探讨了如何通过JavaScript实现在无刷新基础上的局部刷新,提高用户体验。

一,实现不刷新

先看一段代码(PHP例子)

1、表单代码(form.php):

  1. <?php  
  2. header("Content-type: text/html; charset=utf8");  
  3. ?>  
  4. <iframe name="testIframeName" style="display:none;"></iframe>  
  5. <form target="testIframeName" method="post" action="formAction.php">  
  6. <input type="text" name="username"/>  
  7. <input type="password" name="password"/>  
  8. <input type="submit" value=" 提 交 " />  
  9. </form>  
<?php
header("Content-type: text/html; charset=utf8");
?>
<iframe name="testIframeName" style="display:none;"></iframe>
<form target="testIframeName" method="post" action="formAction.php">
<input type="text" name="username"/>
<input type="password" name="password"/>
<input type="submit" value=" 提 交 " />
</form>

2、action代码(formAction.php):

  1. <?php  
  2. echo "<script>alert('test....');</script>";  
  3. ?>  
<?php
echo "<script>alert('test....');</script>";
?>

OK,上面的代码非常简单,但实现了表单提交无刷新....哪这是为什么呢?

哦~其实很基础的东西......就是form标签的属性问题.....如图:



OK,解释就到这里了,虽然例子很简单,很基础....但大多数人不太清楚怎么回事......如果你知道,哈哈,不要喷我....

二,实现局部刷新

 ServletActionContext.getResponse().getWriter().print("<script>parent.getref2()</script>");

一的基础上后台调用前台页面的方法getref2()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值