JQuery / Ajax call onClick to Post data to a file

Hi Wappler Community,
Coming to you to see if something is possible with Wappler.
I have an element that opens/closes a Collapse area.

<h5 dmx-on:click="collapseThread.toggle()">Collapse this thread</h5>

I would also like to send data to a php file (a webhook, really), for example through an Ajax call like

$.ajax({ type: 'POST', url: 'somefile.php', data: { text1: val1, text2: val2 }   });

How/where would I put this in an onClick, and is there a way to do this using Wappler functions?

Thank you!

Could you submit a form with hidden fields, as part of the onclick event?

Hi @TomD, thanks for your answer. It would be more difficult and you’re not explaining how to do that.
Can someone reply to the question how to do an Ajax call since Jquery is loaded on the page?
Thanks :slight_smile:

I probably misunderstood the question, but if you want to click a button to send some POST variables to a PHP file using Ajax, what I suggested would do that - just using Wappler’s standard features.

Eg in lists I’ll typically have buttons (in this case, using checkboxes), which send values to update a database (using Ajax):

image

Obviously, this is not quite the same as what you need, but I would have thought it might be, in essence.