0

In the code given below i am able to append data in MS Edge but when it comes to reading that value i don't have any option given my Microsoft. Is there any workaround to read already appended values ? Any help would be appreciated. Thanks!

let formData = new FormData();
formData.append("Key1", "Key1-Value1");

formData.get("Key1"); // Not Supported in Edge
formData.getAll();    // Not Supported in Edge
formData.entries();   // Not Supported in Edge
formData.keys();      // Not Supported in Edge
formData.value();     // Not Supported in Edge
Coder
  • 48
  • 1
  • 6
  • Can you elaborate on what you're trying to achieve here, possibly by giving an example – Ms.Tamil Nov 08 '18 at 12:30
  • i am trying to support Edge in my case. i need to read those values. – Coder Nov 08 '18 at 12:39
  • The same issue is addressed in https://stackoverflow.com/questions/46306275/formdata-get-and-set-not-working-in-edge-browser-neither-ie. But the question doesn't have any accepted answer. Refer that and you may find something useful there – Ms.Tamil Nov 08 '18 at 12:44
  • yup i have seen it, but the answer is wrong there. – Coder Nov 08 '18 at 12:50
  • Okay. Can you make me understand why you're trying to use FormData particularly here. What is the advantage of FormData over other methods – Ms.Tamil Nov 08 '18 at 13:04
  • what are other methods? tell me methods which i can use instead of FormData – Coder Nov 08 '18 at 13:09
  • You can use vanilla js here like [this](https://stackoverflow.com/questions/3547035/javascript-getting-html-form-values) or you can use a 3rd party library like [this](https://www.npmjs.com/package/form-data) – Ms.Tamil Nov 08 '18 at 13:14

2 Answers2

0

In my opinion, you could define an array to store the entity at the front end, then, you could filter data from the array, instead of the FormData. Please refer to the following code:

var datalist = []; //define an array to store the formdata entities.

let formData = new FormData(); //the formdata, you could send it to server side.

formData.append("Key1", "Key1-Value1");
formData.append('Key1', 'Chris');
formData.append('Key2', 'Bob');

//push data into the array.
datalist.push({ Key: "Key1", value: "Key1-Value1" });
datalist.push({ Key: "Key2", value: "Chris" });
datalist.push({ Key: "Key3", value: "Bob" });

//based on the key value to filter entities.
var entity = jQuery.grep(datalist, function (item) {
    return item.Key == "Key1";
});

//get all keys.
var allkeys = jQuery.map(datalist, function (item) {
    return item.Key;
});

//get all values.
var allvalues = jQuery.map(datalist, function (item) {
    return item.value;
});
Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
0

If I'm at a breakpoint or whatever, I go to Console tab and enter console.log(...formData)

Ron Newcomb
  • 2,886
  • 21
  • 24