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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:46:11+00:00 2026-05-27T09:46:11+00:00

Im trying to submit a form with Ajax here’s my simplified code My index:

  • 0

Im trying to submit a form with Ajax here’s my simplified code
My index:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
        <script>
            $(document).ready(function(){
                $("#addemail").click(function(){
                    var email=$("#email").val();
                    $.ajax({
                        type: "POST",
                        url: "addemail.php",
                        data: "email="+email,
                        success: console.log("success!"), 
                        error: console.log("error!") 
                    });        
                }); 
            });
        </script>
    </head>
    <body>
        <div id="wrapper">
        <h2>Email:</h2>
          <form action="" method="post">
               <table>
                  <tr>
                      <td><label>Années:</label></td>
                      <td><input type="text" id="email" name="email" /></td>
                      <td><input type="submit" id="addemail" value="Ajouter" /></td>
                  </tr>  
              </table>                   
          </form>   
        </div>
    </body>
</html>

And Here my php file

<?php
    $connection =  mysql_connect('localhost', 'XXX', 'XXX');
    $db=  mysql_select_db('mydb', $connection);
    $email= $_POST["email"];
    $query  = 'INSERT INTO users(email) VALUES ("'.mysql_real_escape_string($email).'")';
    mysql_query($query);

?>

My problem is it’s not working… BUT if I put a breakpoint after the ajax it works, it write well the email in the db BUT then I ve the two console log (success! and error! )…
Also if I add action=”addemail.php” to the form, it wont execute Ajax and going to the php page (wich is blank ofc but write well in the db…)

Anyone to help me?

  • 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-27T09:46:12+00:00Added an answer on May 27, 2026 at 9:46 am

    This is wrong:

    success: console.log("success!"),
    

    that way, you are executing the log call straight away, and assigning its result to success.

    What you want is to create two anonymous functions that will get executed when the event happens:

    success: function() { console.log("success!"); },
    error: function() { console.log("error!"); },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to submit my Ajax form using jQuery. However calling the submit() function
I am trying to submit a form with method GET and action index.php?id=3. The
I am trying to use jquery validator plugin and form submit via ajax in
Here is my html form <div id=create> <form action=index.php method=get id=createform> <input type=text name=urlbox
Here's what I'm trying to do. When the 'Submit' form is clicked on my
In the fiddle here http://jsfiddle.net/mjmitche/KvwGw/21/ , when you submit the form, a new form
I am trying to submit a form using Ajax.Updater and have the result of
I'm trying to submit a form with jQuery's $.ajax() function and it works, aside
I'm trying to submit a form and process it with php. Here's what I
I'm basically just trying to submit a form through AJAX and want to show

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.