waken's avatar
Level 1

laravel/lumen problem with cors

larave lumen problem with cors with large data size

0 likes
1 reply
waken's avatar
Level 1

first i'm from china , and my english is not good, so do it in your project, you will find my problem

first: request file, is in port 80 project

`

Document
<script>
$(function(){
    $.ajax({
        url:"http://localhost:7008/response",
        type:"post",
        dataType:'json',
        data:{},
        success:function(result){
            console.log(result)
        }
    })
})

</script>
` port 7008 is lumen project

response function is below

public function response(Request $request) { for ($i = 0; $i < 10; $i++) { $arr[] = [ 'name' => '测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据测试数据', 'value

the middleware in lumen is

` public function handle($request, Closure $next) { if ($request->isMethod('OPTIONS')) { $response = response('', 200); } else { // Pass the request to the next middleware $response = $next($request); }

    // Adds headers to the response
    $response->header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, PATCH, DELETE');
    $response->header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
    $response->header('Access-Control-Allow-Origin', '*');
    // Sends it
    return $response;
}

`

now you change function response the 10 number to 100 or larger

the problem is founded

XMLHttpRequest cannot load http://localhost:7008/response. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

so ,the problem is the laravel/lumen response data size course cors?

this is my chinese english ..... haha 233333

^_^

Please or to participate in this conversation.