@KronosHD

Как передать через AJAX файл?

У меня есть форма:
<form id="form" method="POST" enctype="multipart/form-data">
      <input type="file" name="files">
      <input type="hidden" value="{login}" name="login">
      <button class="button" type="button" onclick="result();">Загрузить</button>
</form>

И есть скрипт - AJAX:
function result() {
   $.ajax({
     'url': "upload/uploader.php",
     'type': "POST",
     'dataType': "html",
     'data': $("#form").serialize(), 
     'success': function(html) {
     $(".result").html(html);
     }
   });
}

Но на uploader.php передаётся всё, кроме файлов. Что делать?

UDP: Можете поправить, чтоб правильно было?
var filename = $("#file").val();
  function result() {
				$.ajax({
                    'url': "upload/uploader.php",
		'type': "POST",
			'dataType': "html",
                    'data': {
                        $("#form").serialize()
                        file: filename
                           },
		     'success': function(html) {
						$(".result").html(html);
					}
				});
			}
  • Вопрос задан
  • 213 просмотров
Пригласить эксперта
Ответы на вопрос 1
Stalker_RED
@Stalker_RED
With HTML5 you CAN make file uploads with Ajax and jQuery. Not only that, you can do file validations (name, size, and MIME-type) or handle the progress event with the HTML5 progress tag (or a div).

© stackoverflow.com/questions/166221/how-can-i-uploa...
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы