Skip to content

onSubmit method #419

@mirannda

Description

@mirannda

I implemented the onSubmit method, these are the two methods that can be used, what do they think of implementing the project?

  onSubmitXHR: function(cmd, url, record) {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.onreadystatechange = function() {
      if (xhr.readyState === 4 && xhr.status === 200) {
        return JSON.parse(xhr.responseText);
      }
    };
    xhr.send(JSON.stringify({ cmd: cmd, record }));
  },
  onSubmit: function(cmd, url, record) {
    (async () => {
      const rawResponse = await fetch(url, {
        method: "POST",
        credentials: "include",
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json"
        },
        body: JSON.stringify({ cmd: cmd, record })
      }).catch(function(error) {
        console.log("Request failed", error);
      });
      const content = await rawResponse.json();
    })();
  },

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions