Access PHP code through Jquery
Step 01 -:
Create a php file named example.php and copy & paste below code to that
<html>
<title> Easy Way For Codings</title>
<header>
<h1>--- Easy Way For Codings PHP example ---</h1>
<script type="text/javascript" src="js/jquery-1.9.0.min.js"></script>
<script>
function onClick()
{
var ajaxurl = 'examplePHPCode.php';
data = {'action':'getModifiedName', 'name': $('#txtname').val()};
$.post(ajaxurl, data, function (response) {
alert(response);
});
}
</script>
</header>
<body>
Enter Value Here: <input type="text" name="txtname" id="txtname"><br><br>
<button type="button" onClick="onClick()">Click Me !</button>
</body>
</html>
Step 02 -:
Create a another php file named examplePHPCode.php and copy & paste below code to that
<?php
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'getModifiedName':
getModifiedName($_POST['name']);
break;
}
}
function getModifiedName($name)
{
echo 'Welcome '.$name;
}
?>
Final Result -:
Download Source Code
0 comments:
Post a Comment