I can not send the correct request to the server to get an answer from it in the form of json string.

Code:

$.ajax({ type: "GET", url: url, dataType: 'json', crossDomain: true, username: 'username', password: 'password', headers: { 'Access-Control-Allow-Origin': '*' }, success: function(response) { console.log(response); } }) 

When you try to send a request, an error occurs:

XMLHttpRequest cannot load URL. It doesn’t give access to the requested resource. Origin 'null' is therefore not allowed access.

  • On the server to which you are sending the request, the header with Access-Control-Allow-Origin should be given. Thus, the server says that remote requests can be made to it, they are disabled by default. - Vasily Barbashev

1 answer 1

The essence of cors is that the server allows you to make requests from other domains. The response header should receive a list of trusted domains, so something like

 header("Access-Control-Allow-Origin: http://example.com"); 

or

 header("Access-Control-Allow-Origin: *"); 

but it's not safe