Answer the question
In order to leave comments, you need to log in
Can't give an AJAX request?
I wanted to give a request for one API with Basic Auth (USERNAME - PASSWORD).
Created index.php - added header header('Access-Control-Allow-Origin: *');
Wrote script - send AJAX on button click
function myFunction(){
var username="xxx";
var password="xxx";
$.ajax({
type: "GET",
url: "xxx",
dataType: 'json',
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
},
success: function (result){
console.log(result)
}
});
Access to XMLHttpRequest at 'xxx' from origin 'https://Мой серв.kz' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question