Все, вроде, просто
1. Форма
<form method="post" enctype="multipart/form-data" onsubmit="sendRequest(); returh false" action="uploadfile.php">
2. Javasscript, который посылает асинхронный запрос
<script type="text/javascript">
var xmlHttp = new XMLHttpRequest();
function sendRequest(){
var oForm = document.form[0];
var aParams = new Array();
var sParam = encodeURIComponent(oForm.elements[0].name);
sParam += "=";
sParam =+ encodeURIComponent(oForm.elements[0].value);
aParams.push(sParam);
var sParam = encodeURIComponent(oForm.elements[0].name);
sParam += "=";
sParam =+ encodeURIComponent(oForm.elements[0].value);
aParams.push(sParam);
sBody = aParams.join("&");
xmlHttp.open("post", oForm.action, true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = serverRespone;
xmlHttp.send(sBody);
}
function serverRespone() {
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){ alert(xmlHttp.responseText);}
else{ alert("err!");}
}
}
</script>
3. PHP скрипт, коорый его обрабатывает.
<?
header("Content-Type: text/plain");
if (isset($_POST['iblock']) ) {
$iblock = $_POST['iblock'];
foreach ( $_FILES as $k => $v ) {
if ( move_uploaded_file($v['tmp_name'], './'.$iblock.'.xls') ) {
echo ("Файл загружен!");
}
}
}?>
Файл грузится. Одна вместо alert на исходной странице, я читаю "Файл загружен!" на uploadfile.php
Где я накосячил?