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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:36:27+00:00 2026-06-01T20:36:27+00:00

Long time reader, first time poster. I’m very new to the world of jQuery

  • 0

Long time reader, first time poster. I’m very new to the world of jQuery and JSON and have been seeing an issue with a login script I’m running.

The end goal is to capture data from a form, pass that data to a PHP file for processing via jQuery.ajax() post, compare the data against a MySQL database for authentication and return a data for either a success of failure.

My problem is that I cannot get the JSON formatted data to be passed from the PHP script back to the jQuery. When viewing the processing with Chrome’s Developer Tools, I see that ‘Login Failure’. I’ve double checked the array $rows by throwing it to my error_log file and it returns properly formatted JSON, but I just can’t for the life of me get it to return to the jQuery file. Any help is appreciated.

My form input:

<!-- BEGIN: Login Page -->
    <section data-role="page" id="login">
        <header data-role="header" data-theme="b">
            <a href="#landing" class="ui-btn-left">Back</a>
        <h1>Please Log In</h1>
        </header>
        <div data-role="content" class="content" data-theme="b">
            <form id="loginForm" action="services.php" method="post">
                <div data-role="fieldcontain">
                    <label for="schoolID">School ID</label>
                    <input type="text" name="schoolID" id="schoolID" value=""  />

                    <label for="userName">Username</label>
                    <input type="text" name="userName" id="userName" value=""  />

                    <label for="password">Password</label>
                    <input type="password" name="password" id="password" value=""  />

                    <h3 id="notification"></h3>
                    <button data-theme="b" id="submit" type="submit">Submit</button>
            <input type="hidden" name="action" value="loginForm" id="action">
                </div>
            </form>
        </div>
        <footer data-role="footer" data-position="fixed" data-theme="b">
            <h1>Footer</h1>
        </div>
    </section>
    <!-- END: Login Page -->

My jQuery Handler:

// Listen for the the submit button is clicked, serialize the data and send it off
    $('#submit').click(function(){
        var data = $("#loginForm :input").serializeArray();
    var url = $("#loginForm").attr('action');

    $.ajax({
        type: 'POST',
        url: url,
        cache: false,
        data: data,
        dataType: 'json',
            success: function(data){
            $.ajax({
                type: 'GET',
                url: "services.php",
                success: function(json){
                alert(json);
                $('#notification').append(json);
                }
            });
            }
        });
    });

And here is my PHP processing:

if (isset($_POST['action'])) {
    $schoolID = $_POST['schoolID'];
    $userName = $_POST['userName'];
    $password = $_POST['password'];

    $sql = "SELECT FirstName, LastName, FamilyID, StudentID, UserID ";
    $sql .= "FROM Users ";
    $sql .= "WHERE SchoolID = '$schoolID' ";
    $sql .= "AND Username = '$userName' ";
    $sql .= "AND Password = '$password'";
    $rs = mysql_query($sql);

    $rows = array();
    while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
        $row_array['firstName'] = $row['FirstName'];
        $row_array['lastName'] = $row['LastName'];
        $row_array['familyID'] = $row['FamilyID'];
        $row_array['studentID'] = $row['StudentID'];
        $row_array['userID'] = $row['UserID'];
        array_push($rows, $row_array);
    }

    header("Content-type: application/json", true);
    echo json_encode(array('rows'=>$rows));
    exit;

    }else{

    echo "Login Failure";
    }
  • 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-01T20:36:29+00:00Added an answer on June 1, 2026 at 8:36 pm

    Look what mistake you are making here it is very simple

     $.ajax({
        type: 'POST',
        url: 'services.php',
        cache: false,
        data: $('#loginForm').serialize(),
        dataType: 'json',
            success: function(data){
                alert(data);
                $('#notification').append(data);
            }
        });
    });
    

    Use serialize function of jquery. And when you have a parameter in success function it is not that ‘data’ you have in this instruction

    data : data,
    

    It is returned from php end it is new data returned on success. To avoid confliction use some thing else like new_data

        success: function(new_data){
            alert(new_data);
            $('#notification').append(new_data);
        }
    

    New data is in json format check it. Use console.log to see in firebug if you are using firefox.

        success: function(new_data){
            console.log(new_data);
            alert(new_data);
            $('#notification').append(new_data);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long time reader, first time poster. I am very new to python and I
Long time reader, first time poster. Any help is greatly appreciated. I have crafted
long time reader, first time poster. I’m coming with an issue that many of
First time poster, long time reader. I've been having a problem with figuring this
First time poster long time reader. I've been playing round with reading in data
first time poster, long time reader so be gentle with me :) See the
(Long time reader of SO, first time asking a q. I'm quite new to
Long time reader, first time poster. Working on a web site at http://www.howardpitch.com/ ,
Long time reader, first time poster. I'm a big noob when it comes to
Long time reader, first time poster. Please be gentle :P I'm working on an

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.