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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:44:57+00:00 2026-06-18T12:44:57+00:00

Currently, I cant access the return data from my jquery ajax. Actually, I dont

  • 0

Currently, I cant access the return data from my jquery ajax. Actually, I dont even know if I am sending any data at all? I just need to send data from a form with JSON to php, and get the response as an array.

Thanks for the help.

HTML/JS/jQuery

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <title>Hello World</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script src="https://github.com/douglascrockford/JSON-js/blob/master/json2.js"></script>

    <script type="text/javascript">
        $(document).ready(function(){
            $("form").submit(function () { 
                var uname = document.getElementById("username").value;
                var pword = document.getElementById("password").value;
                var postData = {
                    username: uname,
                    password: pword
                };
                alert(uname);

                $.ajax({
                url: "test.php",
                type: "GET",
                data: postData,
                dataType: 'json',
                contentType: 'json',
                cache: false,
                success: function (data) {
                        alert(data);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <form action="">
        <input type='text' id="username" name="username" placeholder="Username" />
        <br />
        <input type='password' id="password" name="password" placeholder="password" />
        <br />
        <input type="submit" id="submit" value="Login" />
    </form>
</body>

PHP

echo json_encode(array(
    'username' => $_GET['username'],
    'password' => $_GET['password']
));
  • 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-18T12:44:58+00:00Added an answer on June 18, 2026 at 12:44 pm

    You are creating a handler for the submit event but it seems that you forgot to return false in order to stop the basic submit process.

    A form with an empty action will POST data in the same page (your initial PHP page), so the AJAX call back is sent but just after, you are posting again with basic way.

    Add a return false at the end of the function (just after your AJAX call) and then your form will not be submitted, the AJAX will be sent and you will see the response.

    If you are using Firefox, install Firebug and look at the Network tab to see your request sent by the Ajax call and check your JSON response.

    Good luck.

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

Sidebar

Related Questions

I'm currently retrieving image data from an iSight camera and I'd like to hand
I'm fairly new to JQuery and for some reason I can't get the currently
with $element->children() i cant get all the child elements of current element. but how
Why can't I access muhray 8 lines from the bottom? The print lines that
I know there are quite a few questions concerning access violations, but I have
I'm currently developing an app that uses Core Data. I'm using two stores/configurations, one
I cant seem to get this for the life of me. I cant access
I'm developing for a legacy C++ application which uses ODBC for it's data access.
I'm currently trying to access a physical hard disk as a stream of binary
I'm using OpenAthensSP to return IdP metadata that can potentially access our service. OpenAthensSP

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.