Documentation / Tutorials / SPA

Event: Click - Execute response JS

/ SPA / Event: Click - Execute response JS

This code demonstrates how to send the data to the server and execute the JS  returned by the server

#1. Front side

<button
bind="click"
axn="route.run"
route_ajax="[aw2.get module.slug /].whatever-template-name"
class="btn btn-xs btn-primary"
attribute1="value1"
attribute2="value2"
>Click Event</button>

<div class='xyz-element'>Tag will be prevented</div>

#2. Server side

[aw2.template whatever-template-name]
<script type="spa/axn" axn="core.run_script">
$(document).ready(function(){
alert('back from server');
$('.xyz-element').html('Text updated by JS');
});
</script>
[/aw2.template]

Categories
Most Popular

Leave a Reply

Your email address will not be published.