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,
- Delete file using PHP code : unlink()
- PHP header location function not called
- 403 forbidden error for Image
- Call PHP function on Button click using jquery ajax
- How to Pretty Print JSON in PHP
- Step-by-Step Guide: How to Fix - Error Establishing a Database Connection in WordPress
- PHP Base64 encoding decoding a variable
- 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
- PHP drag and drop file upload tutorial using dropzone.js
- Upload Pdf file using PHP Script
- PHP Warning: Cannot modify header information - headers already sent
- macOS - cannot calculate MAC address: Using fd 9 hv_vm_create HV_ERROR [PHP XAMPP]
- PHP Code for sending Emails
- How to destroy PHP session()
- Installing vue.js in Laravel 8
- PHP 301 Redirect Permanently
- Upload docx file using PHP script
- Save current timestamp in MySQL using PHP mysqi binding
- Copy file from one directory to other in Php
- Failed to load resource: net::ERR_CACHE_MISS PHP
- PHP Script to Upload Images to Server
More Posts:
- How to check your installed version of Git - Git
- Notepad++ select all above or below lines - NotepadPlusPlus
- [Mac] How to Mute People in a Microsoft Teams Meeting - Teams
- Android Studio Button onClickListener Example - Android-Studio
- How to come out of Full Screen Mode Roblox on Mac - MacOS
- How to change background color in Notepad++ - NotepadPlusPlus
- Mac - Open Finder App using Terminal Current Location - MacOS
- How to change SharePoint Online site collection or subsite URL address - SharePoint