Error: JQuery and AJAX

0

I am working with jquery and servlet in java and trying to connect to a method sends me the following error.

  

link : Response to   preflight request does not pass access control check: The   'Access-Control-Allow-Origin' header has a value 'null' that is not   equal to the supplied origin. Origin 'null' is therefore not allowed   access.

This is my method to connect:

$.ajax({
        type: "POST",
        url: "http://localhost:8080/AtnMedicaWeb/atencion/prueba",
        headers: {"Content-Type": "application/json", "Accept": "application/json", 'Access-Control-Allow-Origin' : 'http://localhost:8080'},
        success: function(response){
        },
        failure: function(){
            //location.href = "index.html";
        }
    });
    
asked by Iván Argüello 20.03.2018 в 20:22
source

2 answers

0

This happens because for security the servers block the invocation of processes from clients that do not belong to the same domain. This is solved by giving permission to a particular domain or either or to any domain.

The configuration can be done from the server or from your servlet, if you do it from your servlet, here is an example: link

If you use Tomcat as a server, here is an example configuration: link

    
answered by 22.03.2018 / 16:00
source
1

Apparently the server is not allowing the connection, you could make the configuration of your .htaccess file to allow the connection.

Header set Access-Control-Allow-Origin "*"
    
answered by 22.03.2018 в 05:58