[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Загрузка файла в скрытый iframe
Эли4ка
Здравствуйте!Скажите пожалуйста,есть ли у кого-нибудь примеры загрузки файла в скрытый,динамически создаваемый iframe,просто я искала,нашла один пример,но там все время ошибка с разбором ответа..
<html><head>
<
meta http-equiv="content-type" content="text/html; charset=windows-1251"><script type="text/javascript">
function createIFrame() {
var id = 'f' + Math.floor(Math.random() * 99999);
var div = document.createElement('div');
div.innerHTML = '<iframe style="display:none" src="about:blank" id="'+id+'" name="'+id+'" onload="sendComplete(\''+id+'\')"></iframe>';
document.body.appendChild(div);
return document.getElementById(id);
}

function sendForm(form, url, func, arg) {
if (!document.createElement) return; // not supported
if (typeof(form)=="string") form=document.getElementById(form);
var frame=createIFrame();
frame.onSendComplete = function() { func(arg, getIFrameXML(frame)); };
form.setAttribute('target', frame.id);
form.setAttribute('action', url);
form.submit();
}

function sendComplete(id) {
var iframe=document.getElementById(id);
if (iframe.onSendComplete && typeof(iframe.onSendComplete) == 'function') iframe.onSendComplete();
}

function getIFrameXML(iframe) {
var doc=iframe.contentDocument;
if (!doc && iframe.contentWindow) doc=iframe.contentWindow.document;
if (!doc) doc=window.frames[iframe.id].document;
if (!doc) return null;
if (doc.location=="about:blank") return null;
if (doc.XMLDocument) doc=doc.XMLDocument;
return doc;

//return document.getElementById("txtHint").innerHTML=;
}

var cnt=0;

function uploadComplete(element, doc) {
if (!doc) return;
if (typeof(element)=="string") element=document.getElementById(element);
element.innerHTML='Результат запроса #'+(++cnt)+': '+doc.documentElement.firstChild.nodeValue;
}

</script>

<
/head><body><form id="ajaxUploadForm" method="post" enctype="multipart/form-data" onsubmit="sendForm(this, 'uploadFile.php', uploadComplete, 'resultDiv');return true;">
<label>Файл: <input name="uploadFile" type="file"></label>
<
input value="Загрузить" type="submit">
</
form>
<
input value="Альтернативный вызов загрузки файла" onclick="sendForm('ajaxUploadForm', 'uploadFile.php', uploadComplete, 'resultDiv')" type="button">
<
div id="resultDiv"></div>
<
/body></html>

скрипт загрузчика
<result>Получен файл [<?php echo($_FILES['uploadFile']['name']); ?>]
размером <?php echo($_FILES['uploadFile']['size']); ?> байт</result>


Ответ возвращается в формате XML,но в функции getIFrameXML стопорится,помогите,пожалуйста,исправить.
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.