Search code examples
jqueryuploadimage-uploading

Not being able to set property in form using jquery


Browser: Chrome (Version 78.0.3904.108 ), Firefox: 71.0 (32-bit)

Jquery: 3.3.1

I am trying to upload an image using jquery. So, I tried to use the FormData and set a field with the blob value. Reference source: https://developer.mozilla.org/en-US/docs/Web/API/FormData/set

In the debugger, I found that I am not being able to set any field. Please see the screenshot from the console for a similar example.

enter image description here

Any insight or idea?


Solution

  • I think it's the return type of set which is something different then what you expect. After setting the value please get using the get method of formdata.

    var data = new FormData();
    //This will return undefined
    data.set("a","b");
    // This will return the actual value which is "b"
    data.get('a');