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

  • SEARCH
  • Home
  • 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 4597188
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:13:17+00:00 2026-05-21T23:13:17+00:00

I am trying to send some form without reloading the page and I am

  • 0

I am trying to send some form without reloading the page and I am trying to understand the under-the-hood details therefore not using any JavaScript library:

var http = createRequestObject();
function createRequestObject() {
    var objAjax;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        objAjax=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        objAjax=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objAjax;
}

function display_progress() { ... }    

function upload_file() {
    var request = 'UploaderServlet';
    http.open('post', request);
    http.onreadystatechange = display_progress;
    http.send(null); // HERE PROBABLY THE DATA SHOULD BE SENT
}

<form enctype="multipart/form-data" id="upload_form" name="upload_form" method="POST" action="UploaderServlet" onsubmit="upload_file(); return false;" target="upload_target">
Choose a file <br />  
<input name="file" size="27" type="file" id="file" /> <br/> 
<input type="submit" name="uploadSubmitButton" value="Upload" /><br /> 
<br />  
</form> 

<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>

The upload_file() is called, but if I get it right, the data is not sent. Please advice regarding the correct way to send the data.

  • 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-05-21T23:13:18+00:00Added an answer on May 21, 2026 at 11:13 pm

    Pass attribute in form {url:"",method:"",data:{...},callback:function(){}}

    var ajax=function(){
      try{
        var xml       =new XMLHttpRequest();
        var args      =arguments;
        var context   =this;
        var multipart ="";
    
        xml.open(args[0].method,args[0].url,true);
    
        if(args[0].method.search(/post/i)!=-1){
          var boundary=Math.random().toString().substr(2);
          xml.setRequestHeader("content-type",
                      "multipart/form-data; charset=utf-8; boundary=" + boundary);
          for(var key in args[0].data){
            multipart += "--" + boundary
                       + "\r\nContent-Disposition: form-data; name=" + key
                       + "\r\nContent-type: application/octet-stream"
                       + "\r\n\r\n" + args[0].data[key] + "\r\n";
          }
          multipart += "--"+boundary+"--\r\n";
        }
    
        xml.onreadystatechange=function(){
          try{
            if(xml.readyState==4){
              context.txt=xml.responseText;
              context.xml=xml.responseXML;
              args[0].callback();
            }
          }
          catch(e){}
        }
    
        xml.send(multipart);
      }
      catch(e){}
    }
    

    If you want to get back response you can use this

    var response={};
    ajax.call(response,{...args...})
    

    and you can retrieve all data by response.txt or response.xml

    A bit late update

    As for @Varun question about <input type='file'> uploads, this code can’t handle file uploads directly, in order to send files using this code, you need to perform preprocessing of the raw file data using File API to get non-binary streams (like base64 or any other bin2hex-like form).

    But, since it’s a 2015 year, I can suggest to move from the construction of the multipart streams to something a bit more robust, like the FormData API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to POST some data as if I was using FORM on HTML
I am trying to send some data from a LINQ query in C# to
I am trying to send my dynamically created silverlight 2 page/image to a an
I'm trying to send an email in Java but when I read the body
I am trying to send an email from a site I am building, but
I'm trying to send the output to the console (or colouredconsole) ... which I'm
I'm trying to send email to Active Directory distribution groups. I know you can
i'm trying to send fake keyboard input to an application that's running in a
I am trying to send an anonymous object over a web service. Is there
I am trying to send an HTTP request with the contents of a file

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.