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

  • Home
  • SEARCH
  • 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 6684561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:57:17+00:00 2026-05-26T04:57:17+00:00

how do you call a php function with ajax or javascript or jquery? this

  • 0

how do you call a php function with ajax or javascript or jquery?

this is my php script

function submitmessage() {
    $sent = date(y-m-d-h-m-s);
    $message = $_POST['message'];
    $query = "INSERT INTO chatbox (from,to,message,sent)                            
    VALUES('$fullname','$to','$message','$sent')";
    mysql_query($query) or die(mysql_error());
}
  • 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-26T04:57:18+00:00Added an answer on May 26, 2026 at 4:57 am

    Have the file that the AJAX call connects to be available on the server.

    So lets say your function is in the file: functions.inc.php

    You could have a php file that includes the functions.inc.php and calls the submitmessage function.

    ajax_responder.php:

    require_once 'functions.inc.php';    
    
    if(!empty($_POST)) {
        submitmessage();
    }
    

    Now you can use the URL to the ajax_responder.php to submit messages.

    With jQuery included or written into the page with form:

    function submitmessage(){
        $.post("url_path/ajax_responder.php", { fullname: document.chatbox.fullname.value, message: document.chatbox.message.value } );
    }
    

    Then, instead of submitting a form, you change your submit button into a button that calls the submitmessage javascript:

    <button onclick="submitmessage()">Submit Message</button>
    

    As a side note, for security, I recommend that you do something more with the POST data to ensure that you do not get SQL injection. Since you are already using mysql functions you could try mysql_real_escape_string.

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

Sidebar

Related Questions

I have index.php like this: <script type=text/javascript src=jquery-1.4.2.js></script> <script type=text/javascript src=ajax.js></script> <a href='one.php' class='ajax'>One</a>
I have a JavaScript function, pop_item . I have to call this from PHP,
I'm trying to pass a JavaScript object to a PHP script through jquery.ajax() ,
On my website I use a long polling jquery ajax function. This ajax call
Is there any way to have PHP automatically call a function, before a script
This may be a simple answer, but I'm using jQuery's $.ajax to call a
On my main page I have this jquery code which does an ajax call
I am trying to get a Ajax-call made from jQuery to return a JavaScript
<script type=text/javascript src=http://code.jquery.com/jquery-1.5b1.js></script> <script type=text/javascript src=https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js></script> <input type=text id=textbox> <button id=inlinesubmit_button type=button>submit</submit> <script> function
I'm using wordpress. I make a ajax call with jQuery, PHP echos out a

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.