하나의 AJAX로 이미지와 모든 요소를 어떻게 업로드 할 수 있습니까? 이미지를 업로드하고 데이터베이스에 파일 이름을 보내려고합니다 .... 모든 요소가 잘 작동하지만 이미지 행에 값이 없습니다.
여기 내 AJAX 코드 :
$(document).ready(function() {
$("#FormSubmit").click(function (e) {
e.preventDefault();
if($("#contentText").val()==="")
{
alert("Please enter some text!");
return false;
}
var myData = $("#postA").serialize();
jQuery.ajax({
type: "POST",
url: "response.php",
data:myData,
success:function(response){
$(response).hide().prependTo("#responds").fadeIn("slow");
document.getElementById("postA").reset();
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
그리고 여기 내 양식 코드 :
<form id="postA">
<textarea name="content_txt" id="contentText" ></textarea>
<input type="text" name="id_userto" />
<input type="text" name="thpost" />
<input type="file" name="thpostimg" />
<input type="text" name="thpostvid" />
<input type="text" name="thpostmsc" />
<input type="text" name="thpostlic" />
<input type="hidden" name="content4txt" value="TRUE" />
<button id="FormSubmit">Share</button>
</form>
짧은 답변 : 할 수 없습니다.
ajax로 파일을 게시 할 수 없습니다. 어떻게 비동기 적으로 파일을 업로드 할 수 있습니까?
그러나 그것은 가짜 일 수 있습니다. 이 질문에 대한 대답은 jQuery Ajax가 multipart / form-data (Image / Video)로 양식 요소를 제출하는 데 도움이 될 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다