这是我的代码:
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” 访问。 enter image description here发起的请求的凭据模式 XMLHttpRequest由withCredentials属性控制。
this is error picture,why my method option i already send method post
答案 0 :(得分:0)
当你有多个数据库时,你必须指定你使用的数据库,因为你的Ajax方法不知道哪个数据库调用了哪个Odoo控制器,你可以用这个过滤一个数据库配置文件dbfilter='database_name'
或命令行中的参数:--db-filter database_name
。
我希望这个答案可以对你有所帮助。