안녕하세요, 누구든지 ajax, jquery 및 Struts2를 사용하여 파일을 업로드하는 방법을 알려주십시오. 나는 그물에 많은 튜토리얼을 통과했지만 가능한 해결책을 얻지 못했습니다. 요구 사항은 자바 스크립트 함수가 호출되어야하는 버튼을 클릭 할 때입니다. 자바 스크립트 (jquery)는 Ajax 엔진을 시작하고 아약스는 응답을 얻기 위해 struts 액션을 호출해야합니다. 여기서 요청 및 응답은 페이지를 새로 고치지 않고 IFrame을 사용하지 않고 수행됩니다.Ajax, Jquery 및 Struts2를 사용하여 파일 업로드
0
A
답변
0
iframe을 사용하여 새로 고침없이 데이터를 제출합니다.
i) 내 html은 다음과 같습니다.
1) 양식 태그를 추가하십시오. // 당신은 내 양식 태그는 단지 작업
2) 대상 = "my_iframe"을 추가 변경 붙여 복사 만 할 수 // iframe이 이름은 .. 그것은
이 <div class="bp_up_input">
<form name="banner_image_uploads" id="banner_image_uploads" method="post" action="" target="my_iframe" enctype="multipart/form-data">
<span>
<input type="file" name="banner_image" class="my_vld" lang="Image_path" />
<input type="button" id="banner_image_upload" value="Upload" class="bp_button_style" />
</span>
<input type="hidden" name="slt_store_id" value="" />
<input type="hidden" name="sld_location" value="" />
</form>
</div>
II) 내 자바 스크립트 코드가 아무것도 할 수있다 다음과 같습니다 :
$('#banner_image_upload').live('click',function(){
if($.trim($('input[name="banner_image"]').val()) != '' && $.trim($('select[name="bp_location"]').val()) != '' && $.trim($('#store_names').val()) != ''){
$("iframe").remove(); //Remove previous iframe if present
$("body").append('<iframe id="my_iframe" name="my_iframe" src="" style="display:none;"></iframe>'); //Append iframe to body with id my_iframe
$('#banner_image_uploads').submit();//submit the form with id banner_image_uploads
$("#my_iframe").load(function(){
var val = $("iframe")[0].contentDocument.body.innerHTML; // I use php so I just echo the response which I want to send e.g 250:new and save it in var val.
var data = val.split(':'); // I split the variable by :
var html = '<tr><td><img width="800" height="60" border="0" src="/assets/store_banners/live/'+$.trim($('input[name="sld_location"]').val())+'/'+data[1]+'" id="'+data[0]+'"><a href="#nodo"><img src="/images/delete_trash.png" width="9" height="12" class="image_delete" style="padding-left:37%;"/></a></td></tr>'; // In my case I wanted to upload an image so on success I had to show the image which was uploaded. You can skip this and the below code if you want.
$('.bp_table tbody').append(html); //Append the uploaded image to the container I wanted.
$('input[name="banner_image"]').val(''); //On success I clear the file name
});
}else{
alert('Please Select filters');
}
+0
Can iframe을 사용하지 않고 jquery 및 ajax를 사용하여이 문제를 해결하는 방법을 알려주십시오. –
0
안녕하세요 아래 코드가 작동합니다. 나는 그것이 당신을 도울 것이기를 바랍니다.
JSP 코드 :
<div id="uploadImg">
<s:form id="uploadImgForm" action="strutsaction" method="post" enctype="multipart/form-data">
<s:file name="imgFileUpload" label="Choose file to upload" accept="image/*"></s:file>
<s:submit value="Upload" align="center" id="uploadImgSubmitBtn"></s:submit>
</s:form>
<div>
JQuery와 :
$("#uploadImgSubmitBtn").click(function(e){
// Get form
var form = $('#uploadImgForm')[0];
// Create an FormData object
var data = new FormData(form);
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: "strutsaction.action",
data : data,
cache: false,
processData: false,
contentType: false,
success: function(data){
$('#uploadImg').html(data);
}
});
});
관련 문제
- 1. struts2를 사용하여 이미지 업로드
- 2. jquery ajax 파일 업로드
- 3. JQuery Ajax 파일 업로드
- 4. 파일 업로드 jQuery 플러그인을 사용하여 Ajax 호출에서 여러 파일 업로드
- 5. struts2를 사용하여 웹 응용 프로그램에서 파일 업로드 및 다운로드
- 6. jquery AJAX 및 FormData로 파일 업로드
- 7. 파일 업로드 jQuery AJAX POST
- 8. ajax, jquery, php를 사용하여 파일 업로드
- 9. 간단한 jQuery AJAX 파일 업로드
- 10. django로 jquery ajax 파일 업로드
- 11. ajax 및 servlet을 사용하여 파일 업로드
- 12. Jquery Ajax PHP 파일 업로드
- 13. JQuery AJAX MVC에서 파일 업로드
- 14. Codeigniter를 사용하여 Ajax 파일 업로드
- 15. AJAX 및 CFFILE을 사용하여 파일 업로드
- 16. FormData, AJax 및 CakePHP를 사용하여 파일 업로드
- 17. aspupload를 사용하여 Ajax 파일 업로드
- 18. ajax 및 php 파일 업로드
- 19. Ajax, Json을 사용하여 파일 업로드
- 20. AJax 및 MVC로 파일 업로드
- 21. jquery ajax를 사용하여 파일 업로드
- 22. AJAX 및 PHP를 사용하여 업로드
- 23. jquery.form.js를 사용하여 MVC 4에서 Ajax 파일 업로드
- 24. AJAX MVC 파일 업로드
- 25. jquery ajax 파일 업로드, 전송할 매개 변수
- 26. 큰 파일에서 JQuery Ajax 파일 업로드 실패
- 27. Laravel 및 jQuery 파일 업로드
- 28. Ajax 파일 업로드
- 29. IOS6 및 Safari 사진 업로드 - 파일 API + 캔버스 + jQuery Ajax 비동기식으로 파일 업로드 및 크기 조정
- 30. ajax 파일 업로드 문제 (Node.js, express, jQuery)
당신은 iframe을 사용하지 않고 데이터를 –
감사 제출은 iframe을 사용할 수는 JQuery와 및 아약스 –
나는 항상 사촌은 iframe을 사용 가능합니다 그 쉽고 빠르게 ... 다른 방법을 시도하지 않았습니다 .. 당신은 아래의 코드를 시도 할 수 –