Thread Ajax und Fileupload (10 answers)
Opened by renee at 2007-07-16 17:21

renee
 2007-07-16 17:21
#25167 #25167
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Ich versuche mich gerade daran, einen Mehrfachupload zu "parallelisieren" und zwar mit Ajax. Bin leider kein Ajax-Fetischist ;)

Das ist was ich bisher versucht habe:[html]<html>
<head>
<title>Upload-Test</title>
<script type="text/javascript" language="javascript">
var http_request = false;

function submit_form(url, parameters,id) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}

http_request.onreadystatechange = alertContents(id);
http_request.open('GET', url + '?' + parameters, true);
//http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//http_request.setRequestHeader("Content-type", "multipart/form-data");
//http_request.setRequestHeader("Content-length", parameters.length);
//http_request.setRequestHeader("Connection", "close");
//http_request.send(parameters);
http_request.send( null );
//alert( http_request.status );
}

function alertContents(id) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById('myspan' + id).innerHTML = result;
alert(result);
} else {
alert('There was a problem with the request.');
}
}
alert( http_request.readyState );
}

function get(id) {
var query = "file=" + encodeURI( document.getElementById("file" + id).value );
submit_form('http://localhost/cgi-bin/post.cgi', query, id);
}

function upload_files(){
my_forms = document.forms;
for( var i = 0; i < my_forms.length; i++ ){
var j = i + 1;
if( !document.getElementById("file" + j).value ){
continue;
}
get( j );
}
}
</script>
</head>
<body>
<form action="#" method="post">
<div id="myspan1"><input type="file" name="file1" id="file1"></div>
</form>
<form action="#" method="post">
<div id="myspan2"><input type="file" name="file2" id="file2"></div>
</form>
<input type="button" onclick="upload_files();" value="Dateien hochladen">

</body>
</html>[/html]
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Ajax und Fileupload