Send POST data using XMLHttpRequest

前端 未结 13 1434
说谎
说谎 2020-11-21 04:27

I\'d like to send some data using an XMLHttpRequest in JavaScript.

Say I have the following form in HTML:

<         


        
13条回答
  •  日久生厌
    2020-11-21 04:54

    Short & modern

    You can catch form input values using FormData and send them by fetch

    fetch(form.action, {method:'post', body: new FormData(form)});
    

    function send() {
      let form = document.forms['inputform'];
      fetch(form.action, {method:'post', body: new FormData(form)});
    }

    Look: chrome console>network and click

提交回复
热议问题