我正在尝试上传文件,但无法获取任何内容......这是我的HTML:
<form id=\"captimg\" enctype=\"multipart/form-data\" action=\"captureimg\">
<input type=\"text\" name=\"form_titre_photo_capture_mobile\" placeholder=\"Titre\" class=\"texte_texte_photo_capture_mobile\" id=\"form_titre_photo_capture_mobile\">
<input type=\"file\" capture=\"camera\" accept=\"image/*\" id=\"takePictureField\" name=\"takePictureField\">
</form>
<div class=\"loader\" id=\"spinner_m\">
<span></span>
<span></span>
<span></span>
</div>
<button id=\"FormSubmitPhotoCaptureMobile\" class=\"submit_button\">Envoyer</button>
我的jquery ajax:
$("#FormSubmitPhotoCaptureMobile").click(function (e) {
e.preventDefault();
if($("#form_titre_photo_capture_mobile").val()==="")
{
alert("Veuillez saisir un titre");
return false;
}
$('#FormSubmitPhotoCaptureMobile').hide();
$('#spinner_m').show();
var form_data = new FormData($("#captimg"));
form_data.append("file", takePictureField.files[0]);
form_data.append("titre", $("#form_titre_photo_capture_mobile").val());
jQuery.ajax({
type: "POST",
cache: false,
contentType: false,
processData: false,
url: "captureimg",
data:form_data,
success:function(response){
$('#bar').val(100);
$("#responds").before(response);
$("#form_titre_photo_capture_mobile").val('');
$('#spinner_m').hide();
$('#FormSubmitPhotoCaptureMobile').show();
}
});
});
我发现了很多代码而没有任何工作......请问这个有什么问题? 感谢
答案 0 :(得分:0)
我刚删除了html中的所有斜杠,并将ajax网址更改为captureimg.php
。
在服务器端,我被转储$_FILES
并收到了这个:
Array
(
[file] => Array
(
[name] => apache_pb2.png
[type] => image/png
[tmp_name] => home/tmp/phpA772.tmp
[error] => 0
[size] => 1463
)
)
一切都在Chrome中正常运行。但在Firefox中,我收到此错误TypeError: Value does not implement interface HTMLFormElement. var form_data = new FormData($("#captimg"));