Это мой код:
function make_base_auth(user, password) {
var tok = user;
var hash = btoa(tok);
return "Basic " + hash;
}
xml = new XMLHttpRequest();
var url = 'https://cors-anywhere.herokuapp.com/https://app.sandbox.midtrans.com/snap/v1/transactions';
xml.open('post',url);
$.ajax({
url: "https://cors-anywhere.herokuapp.com/https://app.sandbox.midtrans.com/snap/v1/transactions",
type: "post",
method: 'POST',
dataType: "json",
crossDomain: true,
async: false,
Accept : "application/json",
xhrFields: {
withCredentials: true
},
contentType: "application/json; charset=utf-8",
beforeSend: function(xhr){
xhr.setRequestHeader('Authorization', make_base_auth("SB-Mid-server-aaaa:",""));
},
data: '{"transaction_details":{"order_id":"ORDER-109","gross_amount":75000},"credit_card":{"secure":true},"item_details":[{"id":"ITEM1","price":10000,"quantity":5,"name":"Midtrans wwwwww"},{"id":"ITEM2","price":5000,"quantity":5,"name":"Midtrans wwdwdwdwd"}],"customer_details":{"first_name":"TEST","last_name":"MIDTRANSER","email":"noreply@example.com","phone":"+628123456","billing_address":{"first_name":"TEST","last_name":"MIDTRANSER","email":"noreply@example.com","phone":"081 2233 44-55","address":"Sudirman","city":"Jakarta","postal_code":"12190","country_code":"IDN"},"shipping_address":{"first_name":"TEST","last_name":"MIDTRANSER","email":"noreply@example.com","phone":"0812345678910","address":"Sudirman","city":"Jakarta","postal_code":"12190","country_code":"IDN"}}}',
success: function (data) {
console.log(data);
snap.pay(data.token);
alert("bisa");
},
error: function (xhr, status) {
alert("error");
}
});
Я использую Cors Proxy, но все еще есть ошибка The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*'
.Вот полное сообщение об ошибке:
web.assets_common.js: 1209 Не удалось загрузить https://cors -anywhere.herokuapp.com / https://app.sandbox.midtrans.com/snap/v1/transactions: Ответ на предварительный запрос не проходитпроверка контроля доступа: значение заголовка «Access-Control-Allow-Origin» в ответе не должно быть подстановочным знаком «*», если режим учетных данных запроса «включить».Происхождение 'http://10.0.75.1:8069' поэтому не разрешено.Режим учетных данных запросов, инициируемых , введите здесь описание изображения XMLHttpRequest управляется атрибутом withCredentials.
это изображение ошибки, поэтому мой вариант метода, который я уже отправилметод сообщения