0

I'm trying to append array to a list in the model or append any variable to the formData after getting the data form the form to the FormData just like the code below

function SubmitForm(form) {
    $.validator.unobtrusive.parse(form);
    var formData = new FormData($(form)[0]);

    formData.append('RoleName', 'test');

    if ($(form).valid()) {
        $.ajax({
            type: form.method,
            url: form.action,
            //"datatype": "json"
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                if (data.success) {
                    Popup.dialog('close');
                    dataTable.ajax.reload();

                    $.notify(data.message, {
                        globalPosition: "top center",
                        className: "success"
                    })

                } else {
                    Popup.dialog('close');

                    $.notify(data.message, {
                        globalPosition: "top center",
                        className: "error"
                    })
                }
            }
        });
    }
    return false;

I've check that if I start an empty New FormData() and append the values its work so the exact problem with that code

  var formData = new FormData($(form)[0])

the append won't work after using it ?? any help please

Maho
  • 35
  • 1
  • 6
  • Cannot reproduce – guest271314 Oct 10 '17 at 06:42
  • How do you know the append does not work? Did you iterate through the `formData.entries()` and not find it? Did you not see it server side (would need to see that code if so)? Are you using the correct method, FormData won't work correctly with a GET request? – Patrick Evans Oct 10 '17 at 06:46
  • var form = $(form)[0]; var formData = new FormData(form); you can see detailed answer in here https://stackoverflow.com/questions/21044798/how-to-use-formdata-for-ajax-file-upload – Ferhat BAŞ Oct 10 '17 at 07:28
  • @FerhatBAŞ its same what i did . So the result would be the same – Maho Oct 10 '17 at 07:49
  • @PatrickEvans becouse when i put the value test in to RoleName .And I debug the model in the controller I didn't get the value "TEST" . So I knew that the append doesn't work. Secondly as I explained above instead of using FormData($(form)[0]) I used empty New FormData() and I fill it all by using append the append works. I got the "TEST" in the RoleName . – Maho Oct 10 '17 at 07:57

0 Answers0