ajax(iframe)无刷新提交表单、上传文件
            网络编程 发布日期:2025/11/4 浏览次数:1
         
        
            正在浏览:ajax(iframe)无刷新提交表单、上传文件
            找遍资料得出结果:不能 
不过同时也找到了解决办法,就是用iframe的方式来提交表单,即实现无刷新提交表单又可以上传文件! 
一、HTML代码 
复制代码 代码如下: 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>无刷新提交表单</title> 
<script type="text/javascript"> 
<!-- 
function callback(str){ 
alert(str); 
} 
// --></script> 
</head> 
<body> 
<form name="form1" method="POST" action="../post.php" target="post_frame" enctype="multipart/form-data"> 
<iframe name='post_frame' id="post_frame" style="display:none;" mce_style="display:none;"></iframe> 
<input type="file" name="img" /> 
<input name="power[]" type="text"/> 
<input type="submit" value="完成以上修改" name="submit" /> 
</form> 
</body> 
</html> 
 
二、PHP代码(处理代码) 
这里的代码就想怎么写怎么写了,不过这个里执行完了刚才那个HMTL页面应该要有所表现,这时就要用到上个页面中的 function callback()了 
复制代码 代码如下: 
echo ("<script type=\"text/javascript\">parent.callback('操作成功 ! ')</ script>");