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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:56:36+00:00 2026-06-09T04:56:36+00:00

just trying to get a form to submit with ajax rather than an action

  • 0

just trying to get a form to submit with ajax rather than an action and still having no luck. the php script works and has been testing as working through an action submit.

so far ive looked at examples, read documentation, asked SO questions, but i still have no answers. i need help with this, i was meant to have tested this use case two weeks ago now.

when i submit the page looks like it refreshes but nothing happens. the user account is not inserted into the database, and no alert boxes appear.
can anyone see what goes wrong?

the javascript looks like this:

    $(document).ready(function()
{

$.validator.addMethod("uniqueuser", function(username){
    var response
    $.ajax({
        type: "POST",
        url: "check_username.php",
        data: "username=" + username,
        success: function(server_response){


                if(server_response == '0'){

                    response = true;
                }
                else if(server_response == '1'){

                    response = false;
                }

        }
    });
    return response;
}, "Username is not available");



$("#createaccount).validate({
    debug: false,
    rules:{
        fname:{
            required: true
        }
        surname:{
            required: true
        }
        email:{
            email:true,
            required: true
        }
        location:{
            required:true
        }
        username:{
            minlength: 6,
            required:true,
            uniqueuser:true
        }
        password:{
            required:true,
            minlength: 6
        }
        re_password:{
            required:true,
            equalTo: "#password"
        }
    }


    submitHandler: function(form){
        $.ajax({
            type: 'POST',
            url: 'createaccount2.php',
            data: $("#createaccount").serialize(),
            success: function(response){

                if(response == "1"){
                    alert("That username is already taken!");
                }
                else if(response == "2"){
                    alert("An account is already registered to that email address");
                }
                else if(response == "3"){
                    alert("Your account has been created!");
                }
                else if(response == "4"){
                    alert("Something went wrong, your account could not be created");
                }
            }

        });


    });
});
});

for info on validator: http://docs.jquery.com/Plugins/Validation

  • 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-09T04:56:39+00:00Added an answer on June 9, 2026 at 4:56 am

    There are a bunch of problems within the script. All of them, clearly related to the validator plugin you’re using. One is ASYNCHRONOUS CALLs.

    When you use $.validator (I don’t know this plugin, can you add references?) you try to return response; which is set ASYNC. (after the AJAX gets response by server). That’s why AJAX has callbacks functions, because you don’t know when THAT is gonna be set.

    What’s happening? the return gets executed before the AJAX get’s completed and modifies the variable (but the scope is fine).

    The fix? You will need to dig into that validator plugin in order to see if it supports async validation.

    Otherwise, you will need to setup your own script validation.

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

Sidebar

Related Questions

I'm basically just trying to submit a form through AJAX and want to show
Trying to create and submit form within a javascript call. This code works fine
Using Codeigniter, I am trying to get a php script to run after a
I'm stuck: I'm trying to submit a form using AJAX, but I can't find
I have a php / ajax / javascript form that I am trying to
I'm trying to add an array to my form submit action. Please note I
Just trying to get diff to work better for certain kinds of documents. With
Just trying to get my head around what can happen when things go wrong
Just trying to get some rows out of a database and loop through but
I'm just trying to get into the benefits of using CSS vs. tables, but

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.