Created
April 5, 2020 18:34
-
-
Save terryupton/30e7d5c51ef6b07b4ac101fdb68206d6 to your computer and use it in GitHub Desktop.
Ajax Request using alpineJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button | |
@click="showModal = !showModal | fetch('{{ entry.url() }}', { | |
headers: { | |
'Content-Type': 'application/json', | |
'X-Requested-With': 'XmlHttpRequest' | |
}, | |
}).then(res => res.text()).then(text => { html = text })" | |
class="flex justify-center animate-grow-on-hover--small" | |
> | |
View Profile | |
</button> | |
<main x-data="{showModal: false, html: ''}"> | |
{% include 'pages/team/_partials/_teasers-teamProfiles.twig' %} | |
<div id="bgMask" class="absolute z-0 top-0 right-0 w-full h-full bg-black opacity-75" x-show="showModal"></div> | |
<div id="modal"> | |
<div | |
class="fixed mx-auto inset-x-0 inset-y-0 z-50 max-w-5xl bg-gray-200 md:rounded shadow-2xl" | |
x-show="showModal" | |
@click.away="showModal = false" | |
x-transition:enter="transition ease-out duration-300" | |
x-transition:enter-start="opacity-0 transform scale-90" | |
x-transition:enter-end="opacity-100 transform scale-100" | |
x-transition:leave="transition ease-in duration-200" | |
x-transition:leave-start="opacity-100 transform scale-100" | |
x-transition:leave-end="opacity-0 transform scale-90" | |
> | |
<div x-html="html"></div> | |
</div> | |
</div> | |
</main> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment