question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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();
    })();
  },

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
miranndacommented, Jul 19, 2019

@pmk65, As I see it, perfect, I have tested here and perfect, even can be added the method onSubmit with simplicity. Great job!

image

0reactions
pmk65commented, Jul 31, 2019

Should we close this, as the changes is now available in https://github.com/json-editor/json-editor/tree/develop/2.x

Read more comments on GitHub >

github_iconTop Results From Across the Web

onsubmit Event - W3Schools
onsubmit Event ... Definition and Usage. The onsubmit event occurs when a form is submitted. ... In JavaScript, using the addEventListener() method: object....
Read more >
How onsubmit Event work in JavaScript? Examples - eduCBA
The onsubmit event is performed the triggers is based upon the submit function whenever the client user request in the form-wise data is...
Read more >
HTMLFormElement: submit event - Web APIs | MDN
The submit event fires when the user clicks a submit button ( <button> or <input type="submit">) or presses Enter while editing a field...
Read more >
HTML form action and onsubmit issues - Stack Overflow
The problem I'm having is that my form has the action of going to a new page within our site, and the onsubmit...
Read more >
JavaScript Onsubmit Event with form validation - FormGet
This blog emphasize to JavaScript onsubmit event in which a function is called when form is submitted to validate the fields and if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found