| 1 | import { consumeJson } from "./consumeJson.js" | 
  | 2 | import { exportaAHtml } from "./exportaAHtml.js" | 
  | 3 |  | 
  | 4 |  | 
  | 5 |  | 
  | 6 |  | 
  | 7 |  | 
  | 8 |  | 
  | 9 |  | 
  | 10 |  | 
  | 11 |  | 
  | 12 | export function submitForm(url, event, metodoHttp = "POST") { | 
  | 13 |  | 
  | 14 |  event.preventDefault() | 
  | 15 |  | 
  | 16 |  const form = event.target | 
  | 17 |  | 
  | 18 |  if (!(form instanceof HTMLFormElement)) | 
  | 19 |   throw new Error("event.target no es un elemento de tipo form.") | 
  | 20 |  | 
  | 21 |  return consumeJson(fetch(url, { | 
  | 22 |   method: metodoHttp, | 
  | 23 |   headers: { "Accept": "application/json, application/problem+json" }, | 
  | 24 |   body: new FormData(form) | 
  | 25 |  })) | 
  | 26 |  | 
  | 27 | } | 
  | 28 |  | 
  | 29 | exportaAHtml(submitForm) |