Simple ajax form using javascript no jQuery

前端 未结 9 1069
终归单人心
终归单人心 2020-11-28 11:46

I\'m working with a form for which the mark-up I can\'t change & can\'t use jQuery. Currently the form post the results to a new window. Is it possible to change this to

9条回答
  •  醉酒成梦
    2020-11-28 12:41

    A modern way using fetch would be:

    const formData = new FormData(form);
    fetch(form.action, {
      method: 'POST',
      body: formData
    });
    

    Note browser support and use this polyfil if IE-support is needed

提交回复
热议问题