Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:14:55+00:00 2026-06-18T16:14:55+00:00

i like try to send a POST form with attached files via javascript XMLHttpRequest.

  • 0

i like try to send a POST form with attached files via javascript XMLHttpRequest.

Here is my 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 < document.getElementById('to_upload_files_field').files.length; ++i) {
            document.getElementById('remove_link_' + i).style.display = "none"; }
        for(var i = 0; i < <?php echo $__CONFIG['UPLOAD']['MAX_FILE_AT_ONCE']; ?>; ++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 > <?php echo $USER_DATA['UPLOAD_MAX_FILE_SIZE']; ?>)
                {
                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(<?php echo $USER_DATA['SPACE_MAX']; ?> < (filesize + <?php echo $USER_DATA['SPACE_USED']; ?>))
                {
                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 > (<?php echo $USER_DATA['TRAFFIC_PER_DAY'] - $USER_DATA['TRAFFIC_USED']; ?>) && (<?php echo $USER_DATA['TRAFFIC_PER_DAY'] - $USER_DATA['TRAFFIC_USED']; ?>) != 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', '<?php echo $upload_key; ?>');
            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);

The Script works great and without problems when i’ll send it to “http://www.domain.tld/user/upload/”
but i like to send it to “http://sub.somain.com/store/” and this is not working, why?

Console log by send to “www.domain.tld”:

[12:21:51.085] POST http://www.domain.tld/user/upload/ [HTTP/1.1 200
OK 5ms]

Console log by send to “sub.domain.tld”:

[12:21:17.786] OPTIONS http://sub.domain.tld/store/ [HTTP/1.1 200 OK 7ms]

The servers run the same script, what can i do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:14:56+00:00Added an answer on June 18, 2026 at 4:14 pm

    Javascript will not allow you to make requests between domains, howewer, this behavior can be changed if the server sends Access-Control-Allow-Origin header with the name of whitelisted domain.

    CORS

    As I’ve said, you can yse special response header to allow cross-domain request. This method is called CORS – Cross Origin resource sharing.
    It is used like that:

    header("Access-Control-Allow-Origin: www.domain.tld");
    

    Unfortunatelly, this was only recently introduced and has poor browser support.

    CORS Browser support

    JSONP

    Another method to fire cross domain request is JSONP. This can only be applyed to GET requests. Because you are sending POST, I will not introduce this further.

    Iframe

    You may have forgotten about possibility of using an Iframe. Of course, in that case you will not get any return values and it will be impossible to monitor upload process. But you can still inform user about sucess if you fire alert() function in the iframe. Also, you can reload page from the iframe:

    window.top.location = "domain.com/script.php?upload=sucessfull";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a web form who send post variables like: <form action=teacher.php method=post> <input
I'm using Jersey to send HTTP POST requests like this: MultivaluedMap<String, String> form =
I have some code to update a database table that looks like try {
Rails 3 question. If i send a request like this PUT http://myapp/posts/123?post [title]=hello then
I try to send some data but it seems like the Controller could not
I am trying to post a json string via a form submission ( multi-part
I try to send a multipart form data with a file by using only
I have a form that can be manipulated on the client's browser via javascript
I would like to try Silex but i've some questions. I know to use
I'd like to try out different regexes for the formatlistpat option. Any suggestions as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.