How to react with jQuery on return values of a PHP script? Can I set a cookie without the need of a page reload to access the cookie?

How to react with jQuery on return values of a PHP script? Can I set a cookie without the need of a page reload to access the cookie?

Hi there,

I'm new to jQuery. I would like to learn more about it, so I decided to do a small login form with jQuery v3.3.1 and PHP v7.2.3. The idea is to have the jQuery working on the client and asynchronously calling a small PHP script on the other side. But I run into some questions were I struggled to find answers, I hope somebody here can help me out. 

My login form looks like this (pastebin). If I click the submit button my script.php is called and in the end I return i.e. 0 or 1. Is there a way to react in jQuery dependent on the return value of the  script.php? I have read that there is a success function to keep think asynchronous, but didn't understand where and how to use it. I guess the  success function goes into line 22 on that pastebin link?

If the  script.php returns 0 I would like to load a text inside my the error div without a full page reload and if the  script.php returns 1, a cookie was set in that php script with  setcookie(), than I would like to refresh the whole page with a certain url. How can I do that?

I have read that I need to do a full page reload when I set a cookie to be able to access the new cookie afterwards. Is that true or is there a way to set a cookie and access it without a full page reload?

Thanks for reading and any helpfull tips
Greetings