Submit Formwith AJAX Using ENCTYPE="multipart/form-data"

Discussion in 'Javascript' started by vunet.us@gmail.com, Mar 20, 2007.

  1. Guest

    Hi all,
    I am converting my app to AJAX-based. I have a form that submits some
    data including images. When I use AJAX XmlHttpRequest I am unable to
    submit the form with ENCTYPE="multipart/form-data" (error 500).
    Without ENCTYPE="multipart/form-data", everything goes well. I think
    there is a header I must use in addition, but I cannot seem to find a
    good solution. Can you suggest? Thank you.

    Here is a part of xmlhttp request where I set header:
    ....
    this.req.setRequestHeader("Content-Type", "application/x-www-form-
    urlencoded; charset=UTF-8");
    this.req.send(arguments[3]);
     
    , Mar 20, 2007
    #1
    1. Advertising

  2. Tom Cole Guest

    On Mar 19, 11:07 pm, wrote:
    > Hi all,
    > I am converting my app to AJAX-based. I have a form that submits some
    > data including images. When I use AJAX XmlHttpRequest I am unable to
    > submit the form with ENCTYPE="multipart/form-data" (error 500).
    > Without ENCTYPE="multipart/form-data", everything goes well. I think
    > there is a header I must use in addition, but I cannot seem to find a
    > good solution. Can you suggest? Thank you.
    >
    > Here is a part of xmlhttp request where I set header:
    > ...
    > this.req.setRequestHeader("Content-Type", "application/x-www-form-
    > urlencoded; charset=UTF-8");
    > this.req.send(arguments[3]);


    Well there are more issues than that...You can set your multipart/form-
    data header all day long, but your javascript code is still not going
    to have access to the file data, only the file name. There are other
    methods for this (like hidden iframes) that you should investigate if
    your goal is not to refresh the view of the current page.
     
    Tom Cole, Mar 20, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 20, 9:33 am, "Tom Cole" <> wrote:
    > On Mar 19, 11:07 pm, wrote:
    >
    > > Hi all,
    > > I am converting my app to AJAX-based. I have a form that submits some
    > > data including images. When I use AJAX XmlHttpRequest I am unable to
    > > submit the form with ENCTYPE="multipart/form-data" (error 500).
    > > Without ENCTYPE="multipart/form-data", everything goes well. I think
    > > there is a header I must use in addition, but I cannot seem to find a
    > > good solution. Can you suggest? Thank you.

    >
    > > Here is a part of xmlhttp request where I set header:
    > > ...
    > > this.req.setRequestHeader("Content-Type", "application/x-www-form-
    > > urlencoded; charset=UTF-8");
    > > this.req.send(arguments[3]);

    >
    > Well there are more issues than that...You can set your multipart/form-
    > data header all day long, but your javascript code is still not going
    > to have access to the file data, only the file name. There are other
    > methods for this (like hidden iframes) that you should investigate if
    > your goal is not to refresh the view of the current page.


    If I submit my form the normal html way, with ENCTYPE="multipart/form-
    data", everything works well. But I need the equivalent in AJAX. I do
    not understand how iframes may be related to my problem. I want to do
    a simple AJAX form submission using ENCTYPE="multipart/form-data"...
    Thanks.
     
    , Mar 20, 2007
    #3
  4. Tom Cole Guest

    On Mar 20, 8:42 am, wrote:
    > On Mar 20, 9:33 am, "Tom Cole" <> wrote:
    >
    >
    >
    > > On Mar 19, 11:07 pm, wrote:

    >
    > > > Hi all,
    > > > I am converting my app to AJAX-based. I have a form that submits some
    > > > data including images. When I use AJAX XmlHttpRequest I am unable to
    > > > submit the form with ENCTYPE="multipart/form-data" (error 500).
    > > > Without ENCTYPE="multipart/form-data", everything goes well. I think
    > > > there is a header I must use in addition, but I cannot seem to find a
    > > > good solution. Can you suggest? Thank you.

    >
    > > > Here is a part of xmlhttp request where I set header:
    > > > ...
    > > > this.req.setRequestHeader("Content-Type", "application/x-www-form-
    > > > urlencoded; charset=UTF-8");
    > > > this.req.send(arguments[3]);

    >
    > > Well there are more issues than that...You can set your multipart/form-
    > > data header all day long, but your javascript code is still not going
    > > to have access to the file data, only the file name. There are other
    > > methods for this (like hidden iframes) that you should investigate if
    > > your goal is not to refresh the view of the current page.

    >
    > If I submit my form the normal html way, with ENCTYPE="multipart/form-
    > data", everything works well. But I need the equivalent in AJAX. I do
    > not understand how iframes may be related to my problem. I want to do
    > a simple AJAX form submission using ENCTYPE="multipart/form-data"...
    > Thanks.


    Okay, you can't.
     
    Tom Cole, Mar 20, 2007
    #4
  5. Guest

    On Mar 20, 10:00 am, "Tom Cole" <> wrote:
    > On Mar 20, 8:42 am, wrote:
    >
    >
    >
    > > On Mar 20, 9:33 am, "Tom Cole" <> wrote:

    >
    > > > On Mar 19, 11:07 pm, wrote:

    >
    > > > > Hi all,
    > > > > I am converting my app to AJAX-based. I have a form that submits some
    > > > > data including images. When I use AJAX XmlHttpRequest I am unable to
    > > > > submit the form with ENCTYPE="multipart/form-data" (error 500).
    > > > > Without ENCTYPE="multipart/form-data", everything goes well. I think
    > > > > there is a header I must use in addition, but I cannot seem to find a
    > > > > good solution. Can you suggest? Thank you.

    >
    > > > > Here is a part of xmlhttp request where I set header:
    > > > > ...
    > > > > this.req.setRequestHeader("Content-Type", "application/x-www-form-
    > > > > urlencoded; charset=UTF-8");
    > > > > this.req.send(arguments[3]);

    >
    > > > Well there are more issues than that...You can set your multipart/form-
    > > > data header all day long, but your javascript code is still not going
    > > > to have access to the file data, only the file name. There are other
    > > > methods for this (like hidden iframes) that you should investigate if
    > > > your goal is not to refresh the view of the current page.

    >
    > > If I submit my form the normal html way, with ENCTYPE="multipart/form-
    > > data", everything works well. But I need the equivalent in AJAX. I do
    > > not understand how iframes may be related to my problem. I want to do
    > > a simple AJAX form submission using ENCTYPE="multipart/form-data"...
    > > Thanks.

    >
    > Okay, you can't.


    Really? Oh, so you gave me a hint that if I use a hidden iframe to
    submit data the normal html way, then it is a solution for me... isn't
    it?
     
    , Mar 20, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    8
    Views:
    144,154
    zeeshanakhter2009
    May 26, 2012
  2. Duncan
    Replies:
    0
    Views:
    1,511
    Duncan
    Feb 24, 2006
  3. Matt
    Replies:
    1
    Views:
    11,273
    David Dorward
    Oct 12, 2004
  4. David Lozzi

    Using <form ... enctype="multipart/form-data">

    David Lozzi, Aug 12, 2003, in forum: ASP General
    Replies:
    5
    Views:
    350
    Martin CLAVREUIL
    Aug 12, 2003
  5. Kevin DeValck
    Replies:
    1
    Views:
    770
    7stud --
    May 17, 2011
Loading...

Share This Page