使用jQuery ajaxupload插件实现无刷新上传文件
2017-04-23 13:57
776 查看
项目中会经常用到AJAX无刷新上传图片,但是iframe上传和flash插件都是比较复杂的,所以就找了一个jquery的插件。
代码如下
使用方法如下
<script type="text/javascript"> $(function () { var button = $('#upload'); new AjaxUpload(button, { action: '/upload/imagesAjaxUpload', name: 'upload', onSubmit: function (file, ext) { if (!(ext && /^(jpg|jpeg|JPG|JPEG)$/.test(ext))) { alert('图片格式不正确,请选择 jpg 格式的文件!', '系统提示'); return false; } // change button text, when user selects file button.text('上传中'); // If you want to allow uploading only 1 file at time, // you can disable upload button this.disable(); // Uploding -> Uploading. -> Uploading... interval = window.setInterval(function () { var text = button.text(); if (text.length < 10) { button.text(text + '...'); } else { button.text('上传中'); } }, 200); }, onComplete: function (file, response) { window.clearInterval(interval); // enable upload button this.enable(); var json = eval('(' + response + ')'); button.text('选择文件'); $(".qr").css("display","inline"); $(".qr>img").attr("src",json.file_name); $("input[name='wechat_qr']").val('/uploads/qr/'+json.file_name); //alert(json.file_name); //$("#ajaximg").html("<img src='/uploads/qr/"+json.file_name+"' />"); //$("#wechat_qr").val('/uploads/qr/'+json.file_name); } }); }); </script>
以上所述是小编给大家介绍的使用jQuery ajaxupload插件实现无刷新上传文件,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
相关文章推荐
- 使用ajaxFileUpload.js插件实现ajax无刷新上传文件
- 使用ajaxFileUpload.js插件实现ajax无刷新上传文件
- jquery 实现ajax 上传文件的功能(使用插件 ajaxfileupload)
- jQuery不使用插件及swf实现无刷新文件上传
- MVC文件上传04-使用客户端jQuery-File-Upload插件和服务端Backload组件实现多文件异步上传
- 使用jquery插件uploadify结合commons fileupload实现多文件上传
- 使用ajaxfileupload.js插件实现Ajax方式上传文件
- jQuery ajax + ajaxfileupload.js插件 实现无刷新文件上传
- 使用Ajaxfileupload插件分别实现单文件和多文件上传
- 使用Ajaxfileupload插件分别实现单文件和多文件上传
- jQuery不使用插件及swf实现无刷新文件上传
- 使用Ajaxfileupload插件分别实现单文件和多文件上传
- js使用AjaxFileupload插件实现文件上传
- jQuery上传文件插件AjaxFileUpload的使用
- jQuery插件AjaxFileUpload可以实现ajax文件上传
- 使用隐藏的iframe 隐藏form提交,仿AJax无刷新提交,可以实现无刷新上传文件
- 基于jquery ajax 无刷新 文件批量上传插件 GooUploader整合struts2实现上传
- 使用插件ajaxfileupload通过ajax方式上传文件,在火狐下出错
- 一个简单的jQuery插件ajaxfileupload实现ajax上传文件例子