Hello. I came across a problem when requesting, I get an error .. What is Access control check? What is the problem ? I will be glad to any help.

When transferring data from the form in RegisterController there are no problems .. But when I request, I get an error.

function registerHandler(user){ //Error in Ajax request var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState!=4 || xhr.status!=200){ return window.alert("Problems with request"); } } xhr.open("POST","http://localhost:8080/CouponOnWeb/webappl/register",true); xhr.setRequestHeader('Content-type','application/json;charset=utf-8'); xhr.send(user); } function registerController(){ var user = { username:document.getElementById("reg_user_name").value, firstname:document.getElementById("first_name").value, lastname:document.getElementById("last_name").value, userid:document.getElementById("user_id").value, password:document.getElementById("reg_password").value, email:document.getElementById("reg_email").value } registerHandler(user); } 
  <form id = "registrator" onsubmit = "registerController()"> <label for = "reg_user_name">User name:</label> <input id = "reg_user_name" name = "reg_user_name" type = "text" placeholder = "user name"> <br> <label for = "first_name">First name:</label> <input id = "first_name" name = "first_name" type = "text" placeholder = "first name"> <br> <label for = "last_name">Last name:</label> <input id = "last_name" name = "last_name" type = "text" placeholder = "last name"> <br> <label for = "user_id">Id number:</label> <input id = "user_id" name = "user_id" type = "number" placeholder = "id number"> <br> <label for = "reg_password">Password:</label> <input id = "reg_password" name = "reg_password" type = "password" placeholder = "password"> <br> <label for = "reg_email">Email:</label> <input id = "reg_email" name = "reg_email" type = "email" placeholder = "email"> <br> <input id = "reg_button" name = "reg_button" type = "submit" value = "Register"> </form> 

enter image description here

    1 answer 1

    This means that you are making a request from one domain to another. On another domain you need to place a headline:

     Access-Control-Allow-Origin: your_domain.com 

    or make requests on the same domain.

    Google has a lot of materials on this topic.

    • Andrew - can you throw a link to the material just on my topic? In an Internet, a whole bunch, but if you are familiar with this problem, you probably know what I need. - Maks.Burkov
    • I already wrote to you. You need to either place a header or make requests within the same domain. For example, you from localhost: 300 make a request to localhost: 301, these are different domains and there will be an exception. - blits