Laravel 5 and the weird bug: braces on the back

Whenever I return to history on my Laravel website, the answer I see is this:

{} 

When I move to where I was before, it also shows these curly braces.

The problem does not occur if I run the developer tools in Chrome with the "Disable Cache" option. Content-Type of what returned is really application/json . There is no such problem in Firefox.

This is because one of my Mediators. I wrote AjaxJson middleware to translate all Ajax requests to a JSON response. Oddly enough, when I return to history, Google Chrome makes this Ajax request. It contains this header:

X-Requested-With: XMLHttpRequest

And so $request->ajax() returns true .

This is my middleware:

 <?php namespace App\Http\Middleware; use Closure; use Illuminate\Http\Response; class AjaxJson { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); if (!$request->ajax()) { return $response; } if (!$response instanceof Response) { return $response; } return response()->json($response->getOriginalContent(), $response->status()); } } 

What am I doing wrong?


UPDATE

I found out about the no-store value for the Cache-Control response header. This prevents the use of the Chrome cache when you click the back button. I created the middleware for installing Cache-Control as follows:

Cache-Control: private, max-age = 0, no-cache, no-store

Please let me know guys if you know the best way to solve this problem.

+5
source share
1 answer

Try to process the request after checking:

 public function handle($request, Closure $next) { if ($request->ajax()) { return response()->json($response->getOriginalContent(), $response->status()); } return $next($request); } 
0
source

All Articles