异步上传图片,光用jquery不行,得用jquery.form.js插件

Posted crystalhuhu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异步上传图片,光用jquery不行,得用jquery.form.js插件相关的知识,希望对你有一定的参考价值。

异步上传图片,光用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); 
  } 
  }); 
});













以上是关于异步上传图片,光用jquery不行,得用jquery.form.js插件的主要内容,如果未能解决你的问题,请参考以下文章

jquery如何将页面生成的图片上传到服务器

求一段JS或Jquery异步上传图片的代码

jquery异步上传图片

使用Ajax以及Jquery.form异步上传图片

Jquery异步上传图片

jquery 和 FormData 最简单图片异步上传