POST via ajax para upload file
Eu estou querendo mandar por post file, mas n estou conseguindo. nunca usei ajax via post gostaria de saber qual as configurações necessarias.
// UPLOAD DE IMAGENS
var AjaxRMS;
function AjaxRequest(){
AjaxRMS = false;
if (window.XMLHttpRequest) {
AjaxRMS = new XMLHttpRequest();// Mozilla, Safari
}
else if (window.ActiveXObject) {
try {
AjaxRMS = new ActiveXObject("Msxml2.XMLHTTP");// IE
} catch (e) {
try {
AjaxRMS = new ActiveXObject("Microsoft.XMLHTTP");// IE
} catch (e) {}
}
}
}
function upload(){
var MAX_FILE_SIZE = document.formUpload.MAX_FILE_SIZE.value;
var userfile = document.formUpload.userfile.value;
AjaxRequest();
if(!AjaxRMS){
return;
}
var url ="upload.php";//página onde será feita a consulta
var params = "MAX_FILE_SIZE="+MAX_FILE_SIZE+"&userfile="+userfile;
AjaxRMS.onreadystatechange = Mostra_dados;
AjaxRMS.open("POST", url, true);
AjaxRMS.setRequestHeader("Content-Type", "multipart/form-data");
AjaxRMS.setRequestHeader("Content-length", params.length);
AjaxRMS.setRequestHeader("Connection", "close");
AjaxRMS.send(params);
}
function Mostra_dados(){
if(xmlhttp.readyState==4)
{
document.formUpload.MAX_FILE_SIZE.value = '';
document.formUpload.userfile.value = '';
document.getElementById("resposta").innerHTML=xmlhttp.responseText;
$('#resposta').fadeIn('fast');
$('#uploaded').fadeIn(1000).hide('slow');
}
}
// FIM UPLOAD
obrigado
Discussão (4)
Carregando comentários...