异步上传图片,光用jquery不行,得用jquery.form.js插件,百度一下下载这个插件,加jquery,引入就可以了
<form id="postbackground" method="POST" action="#" enctype="multipart/form-data">
<input name="upload" type="file" id="upload" >
</form>
<input class="handin_bt" type="submit" id="uploadok" value="上传"></td>
$("#uploadok").on("click",function(){
$("#postbackground").ajaxForm({
type:'post',
url:'index.php?controller=testimg&action=TemplateUpload',
dataType: 'json',
success:function(data){
console.log(data.url);
},
error:function(XmlHttpRequest,textStatus,errorThrown){
console.log(XmlHttpRequest);
}
});
});