This can be achieved using ajax, lets see an example,
File : index.php<html>
<head>
<title>Example</title>
<script>
$('.myButton').click(function() {
$.ajax({
type: "POST",
url: "phpFileWithFunction.php"
}).done(function( resp ) {
alert( "Hello! " + resp );
});
});
</script>
</head>
<body>
<input type="button" value="Click" id="myButton" />
</body>
File : phpFileWithFunction.php
<?php
class Foo {
function myFunc() {
return "This data is received from PHP function on button click!";
}
}
$fooObj = new Foo();
echo $fooObj->myFunc();
?>
More Posts related to PHP,
- PHP drag and drop file upload tutorial using dropzone.js
- Copy file from one directory to other in Php
- PHP Base64 encoding decoding a variable
- macOS - cannot calculate MAC address: Using fd 9 hv_vm_create HV_ERROR [PHP XAMPP]
- Upload Pdf file using PHP Script
- Call PHP function on Button click using jquery ajax
- PHP Code for sending Emails
- PHP header location function not called
- Delete file using PHP code : unlink()
- PHP Warning: Cannot modify header information - headers already sent
- Failed to load resource: net::ERR_CACHE_MISS PHP
- Upload docx file using PHP script
- PHP 301 Redirect Permanently
- PHP Script to Upload Images to Server
- Installing vue.js in Laravel 8
- Remove URL Forward Slash Before Single or Double quotes in php.ini
- How to destroy PHP session()
- PHP Fatal error : Call to a member function bind_param() on a non-object
- 403 forbidden error for Image
More Posts:
- #YouMakeStrayKidsStay STRAY KIDS EVERYWHERE ALL AROUND THE WORLD Trending Hashtag - News
- Installing Native Chrome Browser App on M1 Mac Device - Chrome
- How to disable SharePoint subsite creation option for owners - SharePoint
- Android : Remove ListView Separator/divider programmatically or using xml property - Android
- Java Decompiler Eclipse Plugin - Eclipse
- Align left align text in Bootstrap - Bootstrap
- [Event Log] Android Studio performance could be improved - Android-Studio
- Open Current Directory in Finder using Mac Terminal - MacOS