How to inspect FormData?

前端 未结 15 1641
悲&欢浪女
悲&欢浪女 2020-11-22 08:23

I\'ve tried console.log and looping through it using for in.

Here it the MDN Reference on FormData.

Both attempts are in this fi

15条回答
  •  星月不相逢
    2020-11-22 08:34

    I use the formData.entries() method. I'm not sure about all browser support, but it works fine on Firefox.

    Taken from https://developer.mozilla.org/en-US/docs/Web/API/FormData/entries

    // Create a test FormData object
    var formData = new FormData();
    formData.append('key1','value1');
    formData.append('key2','value2');
    
    // Display the key/value pairs
    for (var pair of formData.entries())
    {
     console.log(pair[0]+ ', '+ pair[1]); 
    }
    

    There is also formData.get() and formData.getAll() with wider browser support, but they only bring up the Values and not the Key. See the link for more info.

提交回复
热议问题