D
D
Dmitrii Solovev2015-12-13 18:42:57
JavaScript
Dmitrii Solovev, 2015-12-13 18:42:57

How to authorize via JS (XHR, Fetch)?

For example, there is a server that sends JSON {success: true} if the log/pass is correct and {success: false} if not.

This form authorizes the user when posting to login :

form(id="login-form", method="post", action="/login")

and give it a cookie for the session

. But if I set e.PreventDefault() to onsubmit, and I send the form myself, for example, using the fetch method , then I get json in response, but cookies are not set to the browser.

Googling, I found that cookies are not set for security purposes.

How do you usually solve such problems?
How to correctly submit a form and accept a cookie?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question