Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 使用odoo和ajax方法post Api在localhost中访问控制允许源站_Json_Ajax_Api_Cors_Odoo - Fatal编程技术网

Json 使用odoo和ajax方法post Api在localhost中访问控制允许源站

Json 使用odoo和ajax方法post Api在localhost中访问控制允许源站,json,ajax,api,cors,odoo,Json,Ajax,Api,Cors,Odoo,这是我的代码: 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

这是我的代码:

 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代理,但仍然存在错误
响应中的“访问控制允许原始”头的值不能是通配符“*”
。以下是完整的错误消息:

web.assets\u common.js:1209未能加载 : 对飞行前请求的响应未通过访问控制检查: 响应中“Access Control Allow Origin”标头的值必须为 当请求的凭据模式为时,不能为通配符“*” “包括”。因此,不允许使用源“” 通道由发起的请求的凭据模式 XMLHttpRequest由withCredentials属性控制


当您有多个数据库时,您必须指定您使用的数据库,因为您的Ajax方法不知道数据库调用的哪个Odoo控制器,您可以在配置文件
dbfilter='database\u name'
或命令行中使用此参数筛选一个数据库:
--db filter database\u name


我希望这个答案能对您有所帮助。

在句子中添加大写字母并格式化错误消息。