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' ]( $
for example show this type Category 1 post1 post 2 post3 category 2 post 1 post 2 Category 3 post1 post 2 post3 code : <?php // get all the categories from the database $cats = get_categories (); // loop through the categries foreach ( $cats as $cat ) { // setup the cateogory ID $cat_id = $cat -> term_id ; // Make a header for the cateogry echo "<h2>" . $cat -> name . "</h2>" ; // create a custom wordpress query query_posts ( "cat=$cat_id&post_per_page=100" ); // start the wordpress loop! if ( have_posts ()) : while ( have_posts ()) : the_post (); ?> <?php // create our link now that the post is setup ?> <a href=" <?php the_permalink (); ?> "> <?php the_title (); ?> </a> <?php echo '<hr/>' ; ?> <?php endwhile; endif; // done our wordpress loop. Will start again for each ca
Comments
Post a Comment
If you Satisfied , Please Leave a comment