arrilot / laravel-widgets

Widgets for Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@asyncWidget() causing jQuery errors?

fredbradley opened this issue · comments

Hello,

When I load an async widget, the rest of the jQuery on my page breaks?

with:

Uncaught TypeError: jQuery is not a function

Why might this be? If I remove @asyncWidget() and replace for @widget() it works fine.

Hi, that's strange. The package does not use jquery at all unless you explicitly turn 'laravel-widgets.use_jquery_for_ajax_calls' to true in config.

Here is a javascript code that is injected when you turn @widget to @asyncWdiget

https://github.com/arrilot/laravel-widgets/blob/master/src/Factories/JavascriptFactory.php#L139

Good day!
Looks like this user is using debugbar, which is loaded through the Ajax loaded document...
You have to disable debugbar for these xhr requests, some debugbar logic will be triggered.

I've added a middleware for disabling debugbar on specific routes:

if ($request->is('arrilot/*')) {
    Debugbar::disable();
}

return $next($request);

Closing it for now then

Yes - Thank you so much @bbredewold! That makes sense I guess. Frustrating that I could find any info about it.

@arrilot Could @bbredewold's middleware be added to the package? Or at the very least add this issue to the Readme / install info.

Good day!
Looks like this user is using debugbar, which is loaded through the Ajax loaded document...
You have to disable debugbar for these xhr requests, some debugbar logic will be triggered.

I've added a middleware for disabling debugbar on specific routes:

if ($request->is('arrilot/*')) {
    Debugbar::disable();
}

return $next($request);

If you publish the debugbar config file you can add this route as an "except" parameter.
It's cleaner and never have an error if the package is not installed in production env.