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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:50:21+00:00 2026-06-17T04:50:21+00:00

I am trying to add ajax into my form so I can submit the

  • 0

I am trying to add ajax into my form so I can submit the form without refreshing, however the php echo command is not working. if I take out the ajax it works fine but refreshes on submission. I think it’s a case of trying to get them to work together. I am just learning ajax right now so I dont really know much about it all. Please take a look to see where I’m going wrong

<script type="text/javascript"
 src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>   
<script type="text/javascript">
    $(function() {
        $('form').bind('submit', function(){
            $.ajax({
                type: "POST",
                url: "ajax.html",
                data: $("form").serialize(),
                success: function() {
                    alert("form was submitted");
                }
            });
            return false;
        });
    });
</script>

<?php
    if(isset($_POST['submit'])){
          $a=$_POST['a'];
          $b=$_POST['b'];

           echo $a.$b;
       }
?>

<html>
 <form method='POST'>
    first name:<input type="text" name="a">
    last name: <input type="text" name="b">
               <input type='submit' name='submit'>
  </form>
</html>
  • 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-17T04:50:22+00:00Added an answer on June 17, 2026 at 4:50 am

    It’s probably worth noting that your echo’d PHP code will not be visible, since the ajax response will be getting that information. This isn’t a good example of how to use ajax, since you’re not displaying your result from the ajax call. Something like this would make more sense:

    “ajax.php” PHP file:

    <?php
        if(isset($_POST['submit']))
        {
           $a=$_POST['a'];
           $b=$_POST['b'];
           //Add user name to database here or something
           die($a." ".$b); //Prevents anything after this from being returned
        }
    ?>
    
    <script type="text/javascript"
     src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>   
    <script type="text/javascript">
        $(function() {
            $('form').bind('submit', function(){
                $.ajax({
                    type: "POST",
                    url: "ajax.php",
                    data: $("form").serialize(),
                    success: function(data) {
                        alert("Hello " + data);
                    }
                });
                return false;
            });
        });
    </script>
    
    <html>
     <form method='POST'>
        first name:<input type="text" name="a">
        last name: <input type="text" name="b">
                   <input type='submit' name='submit'>
      </form>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to submit a form using jsRoutes in ajax after first doing
Im trying to submit a form with Ajax here's my simplified code My index:
I'm trying to submit a form and process it with php. Here's what I
I'm trying to add some AJAX to my forms, however I am extremely confused
I'm trying to insert records into DB using AJAX. I'm not sure why, but
Im trying to use jquery and ajax to submit a form and show the
I am using Ajax to submit the info entered into the textarea, and trying
Currently trying at add ajax to a site, after much reading I discovered that
I've been trying to add some AJAX/jQuery script to my site so that only
I'm trying to add details to a database by using ajax and table dynamic

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.