Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Best AJAX path for Wordpress

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 360
    Comment on it

    Hello Reader's if you want to write a custom code for making AJAX hit then you should choose for the best path for that, Open the file admin-ajax.php All ajax request should be made there.

    On in first step open the template file and write the code below:-

    <script type="text/javascript">
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
    </script>
    

    Now open the Javascript File and wite the code below:-

    $.ajax({
            url: ajaxurl,    
            type: "POST",
            cache: false,
            data: data + '&action=sendmail' // or you can define the function
    });
    

    Now open the function.php file and make this function:-

    function send_my_mail(){
    #do your stuff
    }
    
    add_action('wp_ajax_sendmail', 'send_my_mail');
    add_action('wp_ajax_nopriv_sendmail', 'send_my_mail');
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: