public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Alviro Iskandar Setiawan <[email protected]>,
	Fernanda Ma'rouf <[email protected]>,
	Akiekano <[email protected]>
Cc: GNU/Weeb Mailing List <[email protected]>,
	Ammar Alifian Fahdan <[email protected]>,
	Irvan Malik Azantha <[email protected]>,
	Khoiri <[email protected]>,
	Muhammad Irvan Hakim <[email protected]>
Subject: Re: [PATCH buubuu v1 08/10] view: Put the style and JS preload script to top
Date: Sun, 12 Jun 2022 19:46:30 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 6/12/22 7:07 PM, Alviro Iskandar Setiawan wrote:
> +    let xhr = new XMLHttpRequest();
> +    xhr.open("POST", "/auth/register");
> +    xhr.setRequestHeader("Content-type", "application/json");
> +    xhr.send(JSON.stringify(json));

What is the outcome of this code?

 From what I see, what you do are:
1. You create an XHR instance.
2. Open an HTTP POST to "/auth/register".
3. Set the content type to "application/json".
4. Send the stringified JSON.

After that, it does nothing. How do you handle the response from the
server?

This definitely needs a callback to actually work. For example,
setting the onload property like this can do:

   xhr.onload = function () {
      let res = this.responseText;
      // do whatever with res
   };

Or you might as well handle non-successful response with
onreadystatechange like this:

   xhr.onreadystatechange = function () {

      if (this.readyState != 4)
        return;

      let res = this.responseText;
      // do whatever with res
   };

Without such a callback, this only partially works. The client side
will see nothing.

-- 
Ammar Faizi

  reply	other threads:[~2022-06-12 12:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-12 12:06 [PATCH buubuu v1 00/10] Frontend updates Alviro Iskandar Setiawan
2022-06-12 12:07 ` [PATCH buubuu v1 01/10] assets: Create common.js to place common used helpers Alviro Iskandar Setiawan
2022-06-12 12:07 ` [PATCH buubuu v1 02/10] assets: Create common.css to place common used CSS rules Alviro Iskandar Setiawan
2022-06-12 12:07 ` [PATCH buubuu v1 03/10] view: Avoid redefining `get_eid()` function Alviro Iskandar Setiawan
2022-06-12 12:07 ` [PATCH buubuu v1 04/10] view: Rework index.html view Alviro Iskandar Setiawan
2022-06-12 12:07 ` [PATCH buubuu v1 05/10] controller: Crate Index() method in authController Alviro Iskandar Setiawan
2022-06-12 12:26   ` Ammar Faizi
2022-06-12 12:07 ` [PATCH buubuu v1 06/10] server: Load `./assets` directory for `/assets` route Alviro Iskandar Setiawan
2022-06-12 12:07 ` [PATCH buubuu v1 07/10] server: Add route '/' to load the Index Alviro Iskandar Setiawan
2022-06-12 12:07 ` [PATCH buubuu v1 08/10] view: Put the style and JS preload script to top Alviro Iskandar Setiawan
2022-06-12 12:46   ` Ammar Faizi [this message]
2022-06-12 12:07 ` [PATCH buubuu v1 09/10] view: Allow user to navigate between pages Alviro Iskandar Setiawan
2022-06-12 12:07 ` [PATCH buubuu v1 10/10] view: index: Add meta tags for Facebook link preview Alviro Iskandar Setiawan
2022-06-12 12:29   ` Ammar Faizi
2022-06-12 13:19     ` Ammar Faizi
2022-06-24  7:50 ` [PATCH buubuu v1 00/10] Frontend updates Alviro Iskandar Setiawan
2022-06-24  8:04   ` Ammar Faizi
2022-06-24  8:28     ` Alviro Iskandar Setiawan
2022-06-24  9:01       ` Ammar Faizi
2022-06-24  9:09         ` Alviro Iskandar Setiawan
2022-06-24  9:23           ` Ammar Faizi
     [not found]   ` <[email protected]>
2022-06-24  8:34     ` Alviro Iskandar Setiawan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox