Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9334637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T07:06:01+00:00 2026-06-19T07:06:01+00:00

I have a little problem with calling a file in a WordPress plugin using

  • 0

I have a little problem with calling a file in a WordPress plugin using ajax.I have this script:

<script type="text/javascript">
function setVal()
{
    var val = jQuery('#custom_text_message').val()
    alert('Setting the value to "' + val + '"')
    jQuery.post('session.php', {value: val})
    alert('Finished setting the value')
}
jQuery(document).ready(function() {
    jQuery('#custom_text_message').blur(function() {setVal()});
//setTimeout('setVal()', 3000);
});
</script>

But when this function gets called, it shows an error in the console file not found. I want to know if this is the correct way to use ajax in WordPress. If not, how can I call a file which is in the root folder of site name session.php? I’m pretty new to WordPress.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T07:06:03+00:00Added an answer on June 19, 2026 at 7:06 am

    I have solve my problem on my own.First i have define ajaxurl in my themes function.php like below:

    <?php
    add_action('wp_head','pluginname_ajaxurl');
    function pluginname_ajaxurl() {
    ?>
    <script type="text/javascript">
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
    </script>
    <? }
    ?>
    

    And I put the below script on the top of my plugin file.

    <script type="text/javascript">
    function setVal()
    {
        var val = jQuery('#custom_text_message').val()
        var data = {
            action: 'my_action',
            value: val,
        };
    
        jQuery.post(ajaxurl, data, function(response) {
           alert('Got this from the server: ' + response);
        });
    }
    
    jQuery(document).ready(function() {
        jQuery('#custom_text_message').blur(function() {setVal()});
        //setTimeout('setVal()', 3000);
    });
    </script>
    

    and here’s the field, for which i am trying to do in my plugin.

    <textarea name="custom_text_message"  id="custom_text_message"></textarea>
    

    and then I put my action which i m calling to my script in function.php.

    add_action('wp_ajax_my_action', 'my_action_session');
    
    function my_action_session() {
        global $wpdb; // this is how you get access to the database
    
        session_start();
    
        $_SESSION['cus_msg'] = $_POST['value'];
    
        die(); // this is required to return a proper result
    } 
    

    and then call my session value in to my function.That’s all i do and work for me and i hope this will helps someone else.

    Note:
    The wp_ajax_your_action action is for admin if you need to use it on the front end the action would be wp_ajax_nopriv_your_action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with Jquery getJSON function. my json here { entries:
I have a little problem. This is my code: stackPanelShapesContainer = new StackPanel(); InitializeStackPanle();
I have a little problem about Google Maps. I'm using Geocoding (xml) for getting
I have a problem using multiple (2) jQuery plugins. I've googled a little but
I have a little problem calling the button1_click event of form1 from my form2
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,
I have little unusual problem to solve. I need some hint or links to
I have a little problem about the sort direction of a specific column in
I have a little Problem with the app that I'm developing. In the App

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.