I try to use an onclick function. If the user clicks the html button a js function should be done. For this function I need some variables of the php code. How do I get them? If I get them I have to change them. So how do I got them (the changed variables) to php? I thought that ajax could perhaps help me. But how do I use ajax?
Asked
Active
Viewed 30 times
1 Answers
-1
Using a library like Axios or jQuery might help, compared to using Javascript's fetch
function. Here's how you might achieve that using jQuery:
HTML
<button onClick="handleClick()">Click me<button>
Javascript
function handleClick() {
console.log('Clicked the button')
$.get('path/to/script.php', function (data) {
// It helps if the data returned in the PHP script is JSON formatted
console.log(data)
});
}

cameraguy258
- 609
- 2
- 9
- 21