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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:53:31+00:00 2026-05-14T21:53:31+00:00

First and foremost thank you for checking out my problem, and for any help

  • 0

First and foremost thank you for checking out my problem, and for any help you may give!

Okay, so like the title says I’m in need of calling a php function from my index page, which adds a new record in my database as a vote, using JQuery Ajax. This function will return one integer, which will then be printed inside the form button in which it was called from.

Anyone have an idea on how I would accomplish this? Any guidance is appreciated!

Edit:

So if I'm using a template object I can just call the
function using ajax and it will return the output? 
What would I use as the URL? index.php?  

Such as...
function DoVote() {
    $.ajax({
    type:'POST',
    url: 'index.php',
    success: function(data) {
    $('#voteText').html(data);
 }
});

And the form action attribute is posted I’m guessing?

  • 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-05-14T21:53:32+00:00Added an answer on May 14, 2026 at 9:53 pm

    Yes, create a separate PHP file that calls that function and echos the output. Then load that php file with an AJAX request.

    Because PHP is a server side language and jQuery (JavaScript) is Client side you can’t directly call a PHP function with it, the most you can do is load a file. However, if the file has something like <?php echo($object->function()); ?> you can load the file, in essence calling the function.

    I’m not sure that (your addition) is correct.

    In an arbitrary file you have a PHP function:

    <?php
        // Called "otherfile.php"
    
        // Function you're trying to call
        function doSomething($obj)
        {
            $ret = $obj + 5;
    
            return($ret);
        }
    ?>
    

    And you have a file (call it ajaxcall.php) that you will load with that AJAX call.

    <?php
        include("otherfile.php");   // Make the file available, be aware that if that file 
                                    // outputs anything (i.e. not wrapped in a function) it
                                    // may be executed
        // Grab the POST data from the AJAX request
        $obj = $_POST['obj']; 
    
        echo($doSomething());
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First and foremost, I apologize for any vagueness in this question. At this point,
THE EXAMPLE First and foremost, here's my code and problem: http://www.nathanstpierre.com/MBX/showoff.html THE ISSUE So
First, let's get the security considerations out of the way. I'm using simple authentication
I was wondering if someone could help me understand this problem. I prepared a
First and foremost, are there many android developers here? Is this a good place
First of all, sorry for the title. Someone please propose a better one, I
OK first and foremost, performance is most important here so I doubt a map
OK, first and foremost, I am using GNUStep as a way to learn Objective-C,
First I want to explain what am I doing and then my problem. I
First off, I am using Windows XP. I have multiple hard drives and it

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.