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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:41:56+00:00 2026-06-08T16:41:56+00:00

im creating a website and id like to know how to allow ajax to

  • 0

im creating a website and id like to know how to allow ajax to submit form data rather than the html action. ive written a php script that may echo one of several results, and based on that echo, have ajax alert what action has been done by the php script.

for example, if php echo is == 1, alert(“Your account has been created”); if it echo is == 2, alert(“An account is already registered to that email address”); etc etc

ive got some limited experience with ajax from looking at examples and have created a very basic function that will probably be incorrect. just wondering if an ajax expert could fill in the details for me so i can have this functionality. it goes like this:

$("#createaccount").submit(function(){
    $.ajax({
    type: POST,
    url: "createaccount2.php",
    data: 
    success: function(server_response){
        if(server_response == 0){
            alert();
        }
        else if(server_response == 1){
            alert();
        }
        else if(server_response == 2){
            alert();
        }
        else if(server_response == 3){
            alert();
        }

    });
});
  • 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-08T16:41:58+00:00Added an answer on June 8, 2026 at 4:41 pm

    I am not sure what you need exactly but I see the “data:” is empty, you can use serialize to post all input data in your form to your php, like this:

    here is a test form:

    <form id="createaccount">
    <input type="text" name="a" id="a">
    <input type="submit" value="Submit">
    </form>
    

    here is your javascript part:

    $("#createaccount").submit(function(){
        $.ajax({
        type: POST,
        url: "createaccount2.php",
        data: $("#createaccount").serialize(),
        success: function(server_response){
            if(server_response == 0){
                alert('HELLO');
            }
            else if(server_response == 1){
                alert('WORLD');
            }
            else if(server_response == 2){
                alert('AAAA');
            }
            else if(server_response == 3){
                alert('zzZzZzZ');
            }
    
        });
    });
    

    then in your php you can access the data by the $_POST variable:

    <?php
    
    $a=$_POST['a'];
    if($a=='hello'){
        echo "0";
    }elseif($a=='world'){
        echo "1";
    }else{
        echo "2";
    }
    
    ?>
    

    if you enter “hello” and submit it to the php, it will echo “0” and display “HELLO”
    (ps: not tested!)

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

Sidebar

Related Questions

I am creating my website in asp.net 4 and would like to know if
I'm creating a website with structure like this: class main { } class mysql
I'm creating a website and I'd like to prevent the user from logging in
I am creating an online blog website and for each blog post, I'd like
I'm creating a website and I need to style some boxes like this image
I would like to know if there is a website where I could download
I'm currently creating a website a little bit like Digg.com. There are different category
I'm creating a Facebook-like social-network website. For my wall, I have many different kind
I am creating a website using JavaScript/ASP.NET/C#/CSS/HTML/Compact SQL server. I have the majority of
I'm creating a website where I'm doing ajax requests to load some dynamic content

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.