当我尝试使用POST请求访问本地服务器时收到以下错误:
XMLHttpRequest无法加载http://127.0.0.1:8000/api/v1/users/login.请求的资源上不存在"Access-Control-Allow-Origin"标头.原产地" 的http://本地主机:8100 "因此不允许访问.
我的服务器允许CORS,因为我已经通过发送邮递员的请求来测试它并且它可以工作.
这是我在前端的代码:
private headers = new Headers({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS, PUT, PATCH, DELETE',
'Access-Control-Allow-Headers': 'X-Requested-With,content-type',
'Access-Control-Allow-Credentials': true
});
postLogin(data) {
console.log(data);
return new Promise((resolve) => {
this.http.post(this.api + "users/login", data, {headers: this.headers})
.map(res => res.json())
.subscribe(answer => {
this.loggedIn = true;
this.token = answer.token;
resolve(answer);
});
});
}
Run Code Online (Sandbox Code Playgroud)
PS:我没有收到GET请求的错误.
我试图放一个代理,它不会改变任何东西:(
这是我的ionic.config.json:
{
"name": "hardShop",
"app_id": "",
"v2": true,
"typescript": true,
"proxies": [
{
"path": "/api",
"proxyUrl": "http://127.0.0.1:8000"
}
] …Run Code Online (Sandbox Code Playgroud) 我想在laravel 5.4的查询构建器中预先形成此查询
select title, price, price*tauxDiscount/100 as newPrice
from products p, hasdiscount pd, discounts d
WHERE p.idProd = pd.idProd
and d.idDiscount = pd.idDiscount
and now() BETWEEN dateStart and dateEnd
Run Code Online (Sandbox Code Playgroud)
所以我写这个
$products = DB::table('products')
->join('hasDiscount', 'products.idProd', '=', 'hasDiscount.idProd')
->join('discounts', 'discounts.idDiscount', '=', 'hasDiscount.idDiscount')
->select('products.*', '(products.price * discounts.tauxDiscount / 100) as newPrice')
->get();
Run Code Online (Sandbox Code Playgroud)
但他表现出这个错误
[SQLSTATE[42S22]: Column not found: 1054 Unknown column '(products.price
* discounts.tauxDiscount / 100)' in 'field list' (SQL: select
`products`.*, `(products`.`price * discounts`.`tauxDiscount / 100)` as
`newPrice` from `products` inner join …Run Code Online (Sandbox Code Playgroud)