www.webdeveloper.com
Results 1 to 5 of 5

Thread: Uploading files through XMLHttpRequest()

  1. #1
    Join Date
    Oct 2010
    Posts
    4

    Uploading files through XMLHttpRequest()

    There is a form which uploads file to a web page:

    <form method="POST" action="https://woodmin.catsone.com
    /api/add_candidate" enctype="multipart/form-data">

    <input name="resume" type="file">

    </form>

    I need to overwrite it in such way that the same thing would be done through XMLHttpRequest() but so far I haven't suceeded I would be gratefull if someone could tell me how can this be done. My currently code:

    function send(){
    var params=" resume=C://CV-Online.htm";
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("POST","https://woodmin.catsone.com /api/add_candidate",false);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader ("ENCTYPE", "multipart/form-data");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(params);
    window.close()
    }

    Thank you in advance!

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Oct 2010
    Posts
    4
    Thank you for your response, but this is not a solution for me. Maybe I should have added this in my first post:
    I have to make firefox plugin which uploads current html file to a CATS database. This function should be used: http://www.catsone.com/api/add_attachment. So iframe won't work in this case because user must select file by himself. Is there a solution to this problem?

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    And this page...

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    in firefox, you can use the file input's .files collection to graba a string version of the file to be uploaded.

    you would then say something like:
    Code:
    params="data="+encodeURIComponent(input.files[0].getAsBinary());

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles