Hi,

I am kind of successfully uploading files using ajaxForm/ajaxSubmit
and POST. My form has a file input (I am actually using
jquery.MultiFile.js) and some text inputs

e.g.

<input type="file" maxlength="1" class="multi" id="image" name="image"
accept="gif|jpg|jpeg"/>

<label for="fax" class="label">Fax:</label>
<input type="text" size="50" maxlength="50" name="fax" id="fax" class
= "input-box"/>

Here is some code javascript (tried to fiddle with sent data ->
beforeSubmit - no success):

$('#frm_submit_btn').click(function() {

                var UserId = $.trim($('#UserId').val());

                var options =
                {
                   url: "<%= Url.Content("../../Account/Upload") %>",
                   type: 'POST',
                   contentType: 'multipart/form-data',
                   dataType: "text",
                   error: function(XMLHttpRequest, textStatus,
errorThrown) {
                       $('#error_message').text("Server error (file
upload): " + textStatus + " " + errorThrown);
                       return true;
                   },
                   success: function(data) {

                   },
                   beforeSubmit: function(data,form,options)
                   {

                        //data.splice(0,data.length); // delete
content of array
                   },
                   semantic: false
                };


                if (UserId !== "") {
                    $('#item_form').ajaxForm(options);
                }
                else {
                    $("#error_message").empty();
                    $("#error_message").append('Please select a
user.');
                }
            });

This works fine as long as the user selects a file. The file plus the
text form elements are send to the server. Some intercepted traffic:

-----------------------------7d92e142190a
Content-Disposition: form-data; name="UserId"

9bdfa5be-0608-4c14-92cd-defc92d64850
-----------------------------7d92e142190a
Content-Disposition: form-data; name="address_uid"

1
-----------------------------7d92e142190a
Content-Disposition: form-data; name="IsLockedOut"

False

The body(?) has elements that are separated by the boundary string (in
this case 7d92e142190a). However, if the user does not select a file
the body's intercepted traffic looks like this:

UserId=3d7edf4d-84cb-4d03-87fa-26edfbebc6a0&address_uid=3&IsLockedOut=false&username=test&email=

(more like a GET request)

The server cannot deal with this. Any ideas how to change this? Thanks
in advance.

Best wishes,

Christian

Reply via email to