Показать сообщение отдельно
  #9 (permalink)  
Старый 20.01.2014, 23:06
Профессор
Отправить личное сообщение для Veterinar Посмотреть профиль Найти все сообщения от Veterinar
 
Регистрация: 27.12.2013
Сообщений: 167

Поставил вывод responseXML и responseText - и тот, и другой пустые. Почему? - при вызове серверного скрипта возвращается валидный XML. Данные на сервере сохраняются.
Нихрена не понимаю! Где глюк, подскажите!

function log(html) {
  document.getElementById('beforeshow').innerHTML = html;
}

function onSuccess(responseXML) {
	alert('Вызвана onSuccess\n'+responseXML);
}

function onError() {
  log('error');
}

function onProgress(loaded, total) {
  log(loaded + ' / '+ total);
}
//-------------------
var form = document.forms.newphoto;
form.onsubmit = function() {
  var file = this.elements.file.files[0];  
  if (file) upload(file, onSuccess, onError, onProgress);  
}

function upload(file, onSuccess, onError, onProgress) {
  var xhr = new XMLHttpRequest();
  xhr.open("POST", "newphoto.php", true); 
  xhr.onreadystatechange = function() {
		alert('upload: \n'+xhr.responseText+'\n'+xhr.responseXML); // оба пустые! :(
  		onSuccess(xhr.responseText);
		return;
  };
  xhr.send(file);
//  console.log('Прошло');
}

При вызове алерта из функции upload успеваю заметить сообщение и запускает серверный скрипт с XML....

Уважаемые! Помогите пожалуйста!
Ответить с цитированием