1

I tried to do this for working with a part of values from a html-form.

var formData = new FormData();
    formData.append('file', $('#FORM_ADD_LANG_FILE')[0].files[0]);
    formData.append('add_lang_code', $('#FORM_ADD_LANG_CODE').val());
    formData.append('job', jobid);
var post_setting = new Array(false,false);

But in my console it is showing the following error and I don't know why it is

"TypeError: 'append' called on an object that does not implement interface FormData."

I generate the ajax-call by this function

    function getAJAXcall(processData, contentType, formData, callback) {
        var returnValue = {
           url: '".$global['serverurl']."module/".$m['ID']."/code/cms_data.php',
           type: 'POST',
           data: formData,
           success: callback
        };

    if (processData === **false**) returnValue.processData = processData;
    if (contentType === **false**) returnValue.contentType = contentType;
}

And call them up in this way

$.ajax(getAJAXcall(post_setting[0], post_setting[1], formData, function(result) 
  { ...my callback functions... }

Also i try to change the post_setting = new Array(false,false); to true, true but the result was the same

newbieRB
  • 137
  • 1
  • 14

1 Answers1

0

You use the right method call for this, so presumably there's something else wrong.

Could FormData be overwritten by some other library (perhaps a polyfill), that knows nothing of .append()? Check the console of your browser for FormData and see, if you can spot anything fishy there.

You use the result in a jQuery AJAX call, true? Then this answer applies to you. In a nutshell, add

processData: false,

to your AJAX parameters.

Community
  • 1
  • 1
Boldewyn
  • 81,211
  • 44
  • 156
  • 212
  • i try it but the result was the same, i add some more infos in the main question – newbieRB Mar 14 '17 at 18:23
  • maybe the ajax-call function has a error, if i code it by hand "processData:false," it will work fine! – newbieRB Mar 14 '17 at 18:46
  • the function has a important error - so i've update the question, by using processData: false; all will work fine :-) – newbieRB Mar 14 '17 at 18:56