Call PHP Function In JavaScript Using Ajax
how to call php function from javascript function 1. create Folder on WWW Or htdocs (on your computer) 2. create index.php page on your folder and paste this code index.php <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script> function addsearchproduct(x){ // this is JavaScript function $.ajax({ type: 'POST', url: "function.php?f=phpFunction&p="+x, // call php function , phpFunction=function Name , x= parameter data: {}, success: function(data1){ alert(data1); } }); } </script> <input type="button" value="call Php Function" onclick="addsearchproduct('pass value');" /> 3. create function.php page on your folder and paste this code function.php <?php if( function_exists ( $_GET [ 'f' ])) { // get function name and parameter $_GET [ 'f' ]( $
Comments
Post a Comment
If you Satisfied , Please Leave a comment