一个简单的异步上传方法
<! DOCTYPE html> < html> < head> < meta charset ="GB2312" > < title> Insert title here </title > < script type ="text/javascript" src= "jquery.js"></ script > < script type ="text/javascript" > $(document).ready( function (){ $( "#i_1" ).load( function(){ var url = $("#i_1" ).contents().find( "#pic").html(); if (url != null){ $( "#tag_img" ).attr("src" ,url); } }); }); </ script> </ head> < body> < img id= "tag_img" src = "" /> < form enctype ="multipart/form-data" action= "upload_pic.php" method ="post" target= "upload_target"> <input type= "file" name ="img" class= "file" value ="" /> <input type= "submit" name ="uploadimg" value= "上传" /> </ form> < iframe id= "i_1" name = "upload_target"></ iframe > </ body> </ html>
重点:
1.form中的axtion="处理图片的有效页面"
2.form中的target="iframe的name属性值"
3.JS中必须要有可以等待iframe加载完后处理iframe返回过来的图片地址。