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();
?>
- PHP Code for sending Emails
- PHP drag and drop file upload tutorial using dropzone.js
- Delete file using PHP code : unlink()
- Save current timestamp in MySQL using PHP mysqi binding
- Failed to load resource: net::ERR_CACHE_MISS PHP
- PHP Warning: Cannot modify header information - headers already sent
- PHP header location function not called
- How to destroy PHP session()
- Upload docx file using PHP script
- Call PHP function on Button click using jquery ajax
- Upload Pdf file using PHP Script
- 403 forbidden error for Image
- PHP Base64 encoding decoding a variable
- PHP 301 Redirect Permanently
- Copy file from one directory to other in Php
- PHP Script to Upload Images to Server
- Installing vue.js in Laravel 8
- PHP Fatal error : Call to a member function bind_param() on a non-object
- PHP.ini: How to Remove URL Forward Slash Before Single or Double Quotes
- macOS - cannot calculate MAC address: Using fd 9 hv_vm_create HV_ERROR [PHP XAMPP]
- [git] fatal: your current branch 'main' does not have any commits yet - Git
- Convert Instant timestamp into LocalDateTime Java Code Example - Java
- Check Wifi Connection static Android Programming - Android
- Command to check Last Login or Reboot History of Users and TTYs - Linux
- macOS Big Sur compatible Macs List - MacOS
- How to check if an element is hidden using jQuery code? - jQuery
- Shortcuts: How to Toggle Word Wrap in Visual Studio Code (VS Code) - Shortcuts
- How to List the SHA Digest of Docker Images - Docker