How I can upload images and all element with one AJAX? I would to upload images and send filename to database.... All element working fine, but I get nothing value in the images row.
here my AJAX CODE :
$(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);
}
});
});
and here my form code :
<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>
Short Answer: You can't.
You can't post files with ajax How can I upload files asynchronously?
But it can be faked. The accepted answer to this question may help jQuery Ajax Submit form elements with multipart/form-data (Image/Video)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.