关于路由,中间件,Cors,JSONP,这样有什么错误吗?

我在使用vue.js的jsonp获取参数时,浏览器显示200,也获取到了数据,但是不执行success方法。百度上说是跨域请求的问题。我使用了路由+中间价来使用Cors放开跨域。但是报错500,我不知道是中间件还是路由的问题,请大家帮你我看看。
中间件:
<?php

namespace App\Http\Middleware;

use Closure;

class CorsMiddleware
{
/**

  • Handle an incoming request.
  • @param \Illuminate\Http\Request $request
  • @param \Closure $next
  • @return mixed
    */
    public function handle($request, Closure $next)
    {
    $response = $next($request);
    $response->header('Access-Control-Allow-Origin', 'GET,POST');
    $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, Accept');
    $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS');
    $response->header('Access-Control-Allow-Credentials', 'true');
    return $next($request);
    }
    }
    中间件注册:Kernel.php
    protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'callback'=> \App\Http\Middleware\CorsMiddleware::class,
    ];
    }
    路由:Route::get('/front/index/indexLevelOne/{id}',['middleware' => 'auth', function () {
    'Front\IndexController@newGoods'
    }]);
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

报错500,自己不先看下日志报什么错?

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!