Chapters
46 Chapters
|
4:55:39
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
16.
HTML-Returning Ajax Endpoint
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial works perfectly with Stimulus 3!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1", // 1.11.99.1
"doctrine/annotations": "^1.0", // 1.11.1
"doctrine/doctrine-bundle": "^2.2", // 2.2.3
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.8", // 2.8.1
"phpdocumentor/reflection-docblock": "^5.2", // 5.2.2
"sensio/framework-extra-bundle": "^5.6", // v5.6.1
"symfony/asset": "5.2.*", // v5.2.3
"symfony/console": "5.2.*", // v5.2.3
"symfony/dotenv": "5.2.*", // v5.2.3
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/form": "5.2.*", // v5.2.3
"symfony/framework-bundle": "5.2.*", // v5.2.3
"symfony/property-access": "5.2.*", // v5.2.3
"symfony/property-info": "5.2.*", // v5.2.3
"symfony/proxy-manager-bridge": "5.2.*", // v5.2.3
"symfony/security-bundle": "5.2.*", // v5.2.3
"symfony/serializer": "5.2.*", // v5.2.3
"symfony/twig-bundle": "5.2.*", // v5.2.3
"symfony/ux-chartjs": "^1.1", // v1.2.0
"symfony/validator": "5.2.*", // v5.2.3
"symfony/webpack-encore-bundle": "^1.9", // v1.11.1
"symfony/yaml": "5.2.*", // v5.2.3
"twig/extra-bundle": "^2.12|^3.0", // v3.2.1
"twig/intl-extra": "^3.2", // v3.2.1
"twig/twig": "^2.12|^3.0" // v3.2.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.0
"symfony/debug-bundle": "^5.2", // v5.2.3
"symfony/maker-bundle": "^1.27", // v1.30.0
"symfony/monolog-bundle": "^3.0", // v3.6.0
"symfony/stopwatch": "^5.2", // v5.2.3
"symfony/var-dumper": "^5.2", // v5.2.3
"symfony/web-profiler-bundle": "^5.2" // v5.2.3
}
}
What JavaScript libraries does this tutorial use?
// package.json
{
"devDependencies": {
"@babel/preset-react": "^7.0.0", // 7.12.13
"@popperjs/core": "^2.9.1", // 2.9.1
"@symfony/stimulus-bridge": "^2.0.0", // 2.1.0
"@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets", // 1.1.0
"@symfony/webpack-encore": "^1.0.0", // 1.0.4
"bootstrap": "^5.0.0-beta2", // 5.0.0-beta2
"core-js": "^3.0.0", // 3.8.3
"jquery": "^3.6.0", // 3.6.0
"react": "^17.0.1", // 17.0.1
"react-dom": "^17.0.1", // 17.0.1
"regenerator-runtime": "^0.13.2", // 0.13.7
"stimulus": "^2.0.0", // 2.0.0
"stimulus-autocomplete": "^2.0.1-phylor-6095f2a9", // 2.0.1-phylor-6095f2a9
"stimulus-use": "^0.24.0-1", // 0.24.0-1
"sweetalert2": "^10.13.0", // 10.14.0
"webpack-bundle-analyzer": "^4.4.0", // 4.4.0
"webpack-notifier": "^1.6.0" // 1.13.0
}
}
15 Comments
Hi
When my twig template uses a twitter bootstrap behaviour like "tooltip" or "popover", this behaviour is lost after an Ajax loading with "this.resultTarget.innerHTML = await response.text();"
Did you ever experiment this issue? Is there a way to fix it?
Thanks
Cyril
Hey Cyril S.
You can attach the bootstrap tooltip function to a parent element which is always present in your page, or, you can start using Stimulus in your site. If you want to learn more about using Stimulus you can watch our tutorial about Symfony UX https://symfonycasts.com/sc...
Cheers!
I’m still using stimulus and axios to load and refresh this part of html. That’s why I’m surprised by this issue as stimulus is supposed to manage this sort of Ajax refresh habitual problem...
Ohh, you're using Stimulus, that's great! The problem relies on how you're loading bootstrap tooltip now. You can create a Stimulus controller an attach it to all elements that uses the tooltip
Cheers!
Yes, it works!
As I'm using stimulus 2, bootstrap 5 and vanilla JS, I finally did:
`
//bs-tooltip_controller.js
import { Controller } from "stimulus";
import { Tooltip } from "bootstrap";
/ stimulusFetch: 'lazy' /
export default class extends Controller {
connect() {
}
}
`
and in my template, to attach the elements, I used data-controller="bs-tooltip" instead of the bootstrap-classic data-bs-toggle="tooltip"
Thanks a lot Diego!
Cyril
Nice job man! You managed to figure out the missing parts. Cheers!
I didn't know we can use else without an if in twig 😮
Hey Steven,
Yeah, this is a little-known feature from Twig :)
https://twig.symfony.com/do...
Cheers!
oh my, me too,
so far best thing I've learned, thanks! : D
Axios example:
Hey Vladyslav,
Thanks for sharing an Axios example with others :)
Cheers!
Hi,
We are trying to load html content with data-src image paths using lazy loading via native browser after an ajax call. But when we set the response data to this.resultTarget.innerHTML, the images are not loaded (do load if do not use lazy load). Do you know any hack for this issue? thanks a lot!
Hello SamuelVicent
As a tip do not use innerHTML for complex code, try to use
insertAdjacentHTMLor some library that will insert it and trigger correct DOM changes so every listener will be executedCheers!
Hi,
First of all, thank your for answering :)
We also tryied insertAdjacentHTML and no luck: this.contentTarget.insertAdjacentHTML('beforeend', response.data.data.content);
The idea is using stimulus and force re-render contents from an ajax request without doing it manually or using additional libraries, having in mind that lazy load is a built-in feature in chrome and other browsers.
Just asking if you know any kind of setup for this to work automatically. Thanks a lot!
hm interesting question, I can think only about Turbo tech from Stimulus devs probably it's the best use-case for it, however I'm not fully sure about it.
"Houston: no signs of life"
Start the conversation!