告诉我出了什么事?我通过 ajax 将表单发送给处理程序:
<form id="sendmsg" method="POST" enctype="multipart/form-data">
<!-- фотка -->
<input type="file" name="images[]" id="files">
<button class="uk-button uk-button-secondary"><?echo $lang->selectphoto;?></button>
<!-- фотка -->
<textarea id="textarea" class="uk-textarea standart" name="message" maxlength="1500" required></textarea>
<input type="submit" name="send" value="➤" class="uk-button uk-button-secondary send-button" id="sendbtn">
</form>
阿贾克斯:
<script>
$(document).ready( function() {
$("#sendmsg").submit(function(send){
send.preventDefault();
$.ajax({
url: 'updates/sendmsg.php',
type: 'POST',
data: {'files': $('#files')[0].files[0],'idtodb':'<?php echo $partnerid ?>', 'message':$('textarea[name="message"]').val()},
success: function(html){
document.getElementById("sendmsg").reset();
$("#globalresult").html(html);
}
});
});
});
</script>
不选择照片,一切正常,但如果你选择照片,控制台会发誓:
jquery.min.js:2 Uncaught (in promise) TypeError: Failed to execute 'arrayBuffer' on 'Blob': Illegal invocation
at i (jquery.min.js:2:73313)
at Dt (jquery.min.js:2:73205)
at Dt (jquery.min.js:2:73228)
at S.param (jquery.min.js:2:73524)
at Function.ajax (jquery.min.js:2:76904)
at HTMLFormElement.<anonymous> (chat?id=23:509:11)
at HTMLFormElement.dispatch (jquery.min.js:2:43090)
at v.handle (jquery.min.js:2:41074)
使用 FormData 对象。或多或少是这样的: