ts-req

ts-req will issue an XHR request to a server and then update a fragment of a page with a response returned.

There is one limitation - TwinSpark expects you to return a single element for replacement. If you return more, they will be ignored - you can make use of this with help of ts-swap-push.

Terminology

Notes

Examples

Fragment Updating #

Explanation: a issues a request to a server on click, and then is replaced with a new link from a response.

Demo

Update me

Triggering Requests #

Usually requests are triggered on natural interrupts: submit on forms and clicks elsewhere, but sometimes you want more, like triggering on being seen or hovered:

Demo

Hover me!

Indicator #

It's really irritating when you click a link and nothing happens for some time. Luckily TwinSpark makes it really easy: it adds attribute aria-busy="true" to an origin element.

Demo

Just click me

<script> in response (advanced)#

Setting innerHTML to a value which contains script element does not execute JavaScript inside that element. TwinSpark handles that for you, check it out.

Demo

Update me with a script