How to inspect FormData?

前端 未结 15 1335
悲&欢浪女
悲&欢浪女 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

    The MDN suggests the following form:

    let formData = new FormData();
    formData.append('name', 'Alex Johnson')
    for(let keyValuePair of formData.entries()){
        console.log(keyValuePair); //has form ['name','Alex Johnson']
    }
    

    Alternatively

    for (let [key, value] of formData.entries()) {
     console.log(key, ':', value);
    }
    

    Consider adding ES+ Polyfills, in case the browser or environment doesn't support latest JavaScript and FormData API.

    I hope this helps.

提交回复
热议问题