Note that there are some explanatory texts on larger screens.

plurals
  1. POSend files via XMLHttpRequest on another Server
    primarykey
    data
    text
    <p>i like try to send a POST form with attached files via javascript XMLHttpRequest.</p> <p>Here is my Code:</p> <pre><code>window.addEventListener('load', function() { var button = document.getElementById('start_file_upload_button'); button.addEventListener('click', function() { document.getElementById("file_upload_button_button").style.display = "none"; var mfs = document.getElementsByName('MAX_FILE_SIZE')[0].value, to_up_files = document.getElementById('to_upload_files_field'), status = document.getElementById('file_upload_status_text'), errorlog = document.getElementById('file_upload_error_log'), progress = document.getElementById('file_upload_progress_bar'); for(var i = 0; i &lt; document.getElementById('to_upload_files_field').files.length; ++i) { document.getElementById('remove_link_' + i).style.display = "none"; } for(var i = 0; i &lt; &lt;?php echo $__CONFIG['UPLOAD']['MAX_FILE_AT_ONCE']; ?&gt;; ++i) { if(typeof(document.getElementById('to_upload_files_field').files[i]) == "undefined") break; var upload = document.getElementById('to_upload_files_field').files[i], filename = upload.name, filesize = upload.size, mfs = mfs; alert(filename); if(filesize &gt; &lt;?php echo $USER_DATA['UPLOAD_MAX_FILE_SIZE']; ?&gt;) { var errorelem = document.createElement('span'); var errorbreak = document.createElement('br'); errorelem.appendChild(document.createTextNode('Die Datei "' + filename + '" ist zu Groß')); errorelem.appendChild(errorbreak); errorlog.appendChild(errorelem); break; } if(&lt;?php echo $USER_DATA['SPACE_MAX']; ?&gt; &lt; (filesize + &lt;?php echo $USER_DATA['SPACE_USED']; ?&gt;)) { var errorelem = document.createElement('span'); var errorbreak = document.createElement('br'); errorelem.appendChild(document.createTextNode('Die Datei "' + filename + '" past nicht mehr auf die Platte')); errorelem.appendChild(errorbreak); errorlog.appendChild(errorelem); break; } if(filesize &gt; (&lt;?php echo $USER_DATA['TRAFFIC_PER_DAY'] - $USER_DATA['TRAFFIC_USED']; ?&gt;) &amp;&amp; (&lt;?php echo $USER_DATA['TRAFFIC_PER_DAY'] - $USER_DATA['TRAFFIC_USED']; ?&gt;) != 0) { // SPERRE EINBAUEN DAS ES NUR GEPRÜFT WIRD WENN DIE TRAFFIC ÜBERWACHUNG AKTIVIERT IST var errorelem = document.createElement('span'); var errorbreak = document.createElement('br'); errorelem.appendChild(document.createTextNode('Die Datei "' + filename + '" braucht mehr traffic als du hast')); errorelem.appendChild(errorbreak); errorlog.appendChild(errorelem); break; } status.innerHTML = "Lade " + filename + " hoch..."; var request = new XMLHttpRequest(); request.open('POST', 'http://www.domain.tld/user/upload/', true); request.setRequestHeader('Content-Type', 'multipart/form-data'); request.upload.addEventListener('progress', function(evt) { var uploaded = Number((100 / evt.total) * evt.loaded).toFixed(2); progress.innerHTML = "Upload zu " + uploaded + "% fertig"; if(uploaded = 100.00) { progress.innerHTML = "Datei wird verarbeitet... Bitte warten..."; } }, false); request.addEventListener('load', function(evt) { alert("lol2"); }, false); var data = new FormData(); data.append('upload_key', '&lt;?php echo $upload_key; ?&gt;'); data.append('MAX_FILE_SIZE', mfs); data.append('file', upload); request.send(data); request.onload = function() { if(this.status == 200) { alert("lol"); } else { alert("Some Upload Error"); } }; } }, false); }, false); </code></pre> <p>The Script works great and without problems when i'll send it to "<a href="http://www.domain.tld/user/upload/" rel="nofollow">http://www.domain.tld/user/upload/</a>" but i like to send it to "<a href="http://sub.somain.com/store/" rel="nofollow">http://sub.somain.com/store/</a>" and this is not working, why?</p> <p>Console log by send to "www.domain.tld": </p> <blockquote> <p>[12:21:51.085] POST <code>http://www.domain.tld/user/upload/</code> [HTTP/1.1 200 OK 5ms]</p> </blockquote> <p>Console log by send to "sub.domain.tld": </p> <blockquote> <p>[12:21:17.786] OPTIONS <code>http://sub.domain.tld/store/</code> [HTTP/1.1 200 OK 7ms]</p> </blockquote> <p>The servers run the same script, what can i do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload