아약스를 사용하여 datas 파일을 업로드하려고합니다. 나는 그것이 새로운 FormData()를 사용하고있다 아약스 혼자 업로드 된 파일을 보낼 때업로드 된 파일을 보내고 아약스로 데이터 입력
<body>
<input type="text" id="name" value="test" />
<input type="file" id="pic" accept="image/*" />
<input id = "submit" type="submit" />
</body>
; 여기 내 HTML 양식입니다
var file_data = $('#pic').prop('files');
var form_data = new FormData();
form_data.append('file', file_data);
alert(form_data);
$.ajax({
url: 'test.php', // point to server-side PHP script
dataType: 'text', // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(php_script_response){
alert(php_script_response);
}
});
그러나 Idon't은 다음 예제와 같이 데이터
와var DATA = 'name='+name;
$.ajax({
url: "test.php",
type: "post",
data: DATA,
success: function (response) {
console.log($response);
},
});
감사
당신이 폼 태그를 포함해야합니다 모든
그냥 하나의 아약스에 'form_data.append ('input_name ', $ ('name ') .Val());' –