새로 고침 없이 파일을 업로드하기 위한 jQuery ajaxupload 플러그인에 대한 자세한 설명

小云云
풀어 주다: 2018-01-17 13:42:29
원래의
1426명이 탐색했습니다.

AJAX 새로고침하지 않은 업로드 이미지는 프로젝트에서 자주 사용되는데, iframe 업로드와 플래시 플러그인은 상대적으로 복잡해서 jquery 플러그인을 찾았습니다. 다음은 jQuery ajaxupload 플러그인을 사용하여 새로 고침 없이 파일을 업로드하는 방법을 소개하는 예제 코드입니다. 필요한 친구들이 참고하면 도움이 될 것입니다.

코드는 다음과 같습니다

사용 방법은 다음과 같습니다

<script type="text/javascript">
$(function () {
var button = $(&#39;#upload&#39;);
new AjaxUpload(button, {
action: &#39;/upload/imagesAjaxUpload&#39;,
name: &#39;upload&#39;,
onSubmit: function (file, ext) {
if (!(ext && /^(jpg|jpeg|JPG|JPEG)$/.test(ext))) {
alert(&#39;图片格式不正确,请选择 jpg 格式的文件!&#39;, &#39;系统提示&#39;);
return false;
}
// change button text, when user selects file
button.text(&#39;上传中&#39;);
// 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 + &#39;...&#39;);
} else {
button.text(&#39;上传中&#39;);
}
}, 200);
},
onComplete: function (file, response) {
window.clearInterval(interval);
// enable upload button
this.enable();
var json = eval(&#39;(&#39; + response + &#39;)&#39;);
button.text(&#39;选择文件&#39;);
$(".qr").css("display","inline");
$(".qr>img").attr("src",json.file_name);
$("input[name=&#39;wechat_qr&#39;]").val(&#39;/uploads/qr/&#39;+json.file_name);
//alert(json.file_name);
//$("#ajaximg").html("<img src=&#39;/uploads/qr/"+json.file_name+"&#39; />");
//$("#wechat_qr").val(&#39;/uploads/qr/&#39;+json.file_name);
}
});
});
</script>
로그인 후 복사

관련 권장 사항:

새로 고침 없이 파일 업로드 기능을 구현하는 ajax에 대한 자세한 설명 예시

jQuery 없이 이미지 업로드 플러그인 새로 고침

새로 고침 없이 업로드할 수 있는 JavaScript 미리보기 이미지 기능

위 내용은 새로 고침 없이 파일을 업로드하기 위한 jQuery ajaxupload 플러그인에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!