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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:39:52+00:00 2026-06-14T23:39:52+00:00

I have been developing a registration form and slowly but surely I have been

  • 0

I have been developing a registration form and slowly but surely I have been learning some javascript and jquery along the way, to further support my knowledge of that and all. I have come across a problem however, the problem is I can’t get the response from a AJAX request.

My AJAX request is in a separate function, I have multiple purposes for it. I have put alert();’s in the code for debugging purposes.

function validate_input ( input, type ) {
    $.ajax({
            type:'post',
            url: 'ajax_request.php',
            data: "type=" + type + "&input=" + input,
            success: function( response ) {
            if( response == "true" || response == "false" ) {
                alert( "working" );
                console.log(response);
                return response;
            } else {
                alert( "AJAX/jQuery Error" );
                alert( "Reponse !== true or false" );
            }
        }
    });
}

I can confirm that the ajax_request.php file is echoing true or false correctly, however, for those interested here is the coding.

if (!defined('BASEPATH') &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')
exit('Direct Access to this file has been disabled.');

include('core/db.php');
$validateType = intval( $_POST['type'] );
$input = escape_string( $_POST['input'] );

if( $validateType == 1 ) // validate username
{
    echo ( user_exists( $input ) ? "true" : "false" );
} else if( $validateType == 2 ) // validate email
{ 
    echo "true"; // not coded yet
}

Finally, I call the function when it is necessary( using .blur() ), you can see below;

var username_value = "Jake"; // for debugging purposes, var definitely contains something
validate_input( username_value, 1 );
alert( validate_input( username_value, 1 ) ); alerts "undefined"

I am just wondering if anyone can see any issues with the code that would be causing this, and please don’t suggest for me to use a validator plugin, that is not an answer to the question.

Thanks,

  • 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-14T23:39:54+00:00Added an answer on June 14, 2026 at 11:39 pm

    Ajax calls are asynchronous, you can’t return the response like that. Using ajax you define a callback function which is called when the response is received. Code execution does not stop and wait for the response before continuing.

    So you need to do whatever you want to do within the success function, or call another function from there.

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

Sidebar

Related Questions

I have been developing the application for drawing and I have some problems: the
I have been developing my first mobile site with jQuery Mobile and you can
I have been developing a parental control software program for my company, but have
I have been developing some software and want to give it version numbers. How
I have been developing a game in the HTML5/Javascript new canvas feature, and all
I have been developing a jquery widget that extends ui.mouse. The widget needs to
I have been developing a C# windows form application in XP. It all works
I have been developing for some time now, and I have not used pointers
I have been developing some page and I need to clear a content of
I have been developing iOS apps for a while but they all deal with

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.