小编bon*_*dif的帖子

请求的资源 - 离子2应用程序中不存在"Access-Control-Allow-Origin"标头

当我尝试使用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)

http cors typescript ionic-framework angular

10
推荐指数
1
解决办法
4万
查看次数

查询生成器laravel中的算术运算

我想在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)

php mysql sql laravel laravel-5

3
推荐指数
1
解决办法
3826
查看次数

标签 统计

angular ×1

cors ×1

http ×1

ionic-framework ×1

laravel ×1

laravel-5 ×1

mysql ×1

php ×1

sql ×1

typescript ×1