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 9213301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:42:53+00:00 2026-06-18T01:42:53+00:00

wonder if anyone can help; I’m trying to implement some ajax through jquery onto

  • 0

wonder if anyone can help; I’m trying to implement some ajax through jquery onto a form in a wordpress template.

The jquery is working, and the I can log a console message in the sucess: section, but the data is 0, when it should be calling the php function (at the moment on the same page, and I can call this directly)

so I guess the jquery is working, the admin-ajax is being called, its just the php function is not being called. Any ideas what I could be doing wrong ? I don’t fully understand hooks, so perhaps that is an issue – that I need to hook something in somewhere?

jquery (domain would replace comments)

<script type="text/javascript">
    jQuery(function ($) {
        $( "#movies" ).autocomplete({
                minLength:2,
                delay:500,
                source: function( request, response ) {
                    $.ajax({
                        type: 'POST',
                        url: "http://<!--domain here -->/wp-admin/admin-ajax.php",
                        dataType: 'json',
                        data: {
                            action: 'getMoviesForCode',
                            searchString: $("#movies").val()
                        },
                        success: function( data ) {
                            response(data);
                            console.log('jjj'+data);
                        }
                    });
                }           
        });
    });
    </script> 

php function (on same page)

<?php

    function getMoviesForCode(){
echo "
        <script type=\"text/javascript\">
        alert(\"hh\");
        </script>
    ";
   $searchString = $_POST['searchString'];
   $results = va_getMoviesForCode($searchString);  
  $results = json_encode($results);
  die($results);
}
 ?>

Thanks,

  • 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-18T01:42:55+00:00Added an answer on June 18, 2026 at 1:42 am

    You’re doing it wrong. You php function should be in your theme’s functions.php file.

    You should then hook the function to wp_ajax_[your_action] and wp_ajax_nopriv_[your_action].

    Example of what should be in your functions.php :

    function getMoviesForCode(){
    echo "
            <script type=\"text/javascript\">
            alert(\"hh\");
            </script>
        ";
       $searchString = $_POST['searchString'];
       $results = va_getMoviesForCode($searchString);  
      $results = json_encode($results);
      die($results);
    }
    add_action('wp_ajax_getMoviesForCode', 'getMoviesForCode');
    add_action('wp_ajax_nopriv_getMoviesForCode', 'getMoviesForCode');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if anyone can help with a jQuery problem I am having. I
I'm a newbie programmer working with jQuery and wonder if anyone can help me
I wonder if anyone can help me filter this data in some way? Here
Hi I wonder if anyone can help, I'm trying to create a responsive site
I wonder is anyone can help me with this annoying problem. Trying to insert
Having a bit of config trouble in Wordpress and wonder if anyone can help.
I wonder if anyone can help improve my understanding of JOINs in SQL. [If
I wonder if anyone can help - I have this error showing recently when
I wonder if anyone can help me to understand where I could be going
I wonder if anyone can help? After Google announced that it will take note

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.