submit the form using ajax

后端 未结 8 889
栀梦
栀梦 2020-12-05 10:17

I\'m developing an application (a kind of social network for my university). I need to add a comment (insert a row in a specific database). To do this, I have a HTML form in

8条回答
  •  情歌与酒
    2020-12-05 10:45

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

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

    function send(e,form) {
      fetch(form.action,{method:'post', body: new FormData(form)});
    
      console.log('We send post asynchronously (AJAX)');
      e.preventDefault();
    }
    Look on chrome console>network before 'submit'

提交回复
热议问题