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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:04:06+00:00 2026-06-01T11:04:06+00:00

This Ajax is not retrieving any information from its’ PHP file as it should,

  • 0

This Ajax is not retrieving any information from its’ PHP file as it should, and when inspecting the Javascript in Firebug I noticed that responseText is returning undefined.

Here is the Javascript:

function getTeams(sport)
{
    var req = new XMLHttpRequest();
    var nextTeam, nextOption;

    // callback function, using "closure"
    req.onreadystatechange = function()
    {
        if( (req.readyState == 4) && (req.status == 200) )
        {
            var result = req.responseText;

            // array teams created here
            var teams = result.split(", ");

            for(var i = 0; i < teams.length; i++)
            {
                nextTeam = teams[i];
                nextOption = new Option(nextTeam);

                /* add the new option to the option list
                 ("null" for IE5, "-1" for all other browsers) */
                try
                {
                    document.getElementById("teamsList").add(nextOption, -1);
                }
                catch(e)
                {
                    document.getElementById("teamsList").add(nextOption, null);
                }
            }
        }
    } // end of closure

    req.open("GET", "favoriteSport.php?sport=" + sport, true);
    req.send(null);
}<br /><br />

Here is the PHP:

<?php
    $sport = $_GET["sport"];

    $teams = array("basketball" => "Atlanta Hawks, Chicago Bulls, New York Knicks",
                    "baseball" => "Atlanta Braves, Chicago Cubs, New York Yankees",
                    "football" => "Atlanta Falcons, Chicago Bears, New York Giants");

    return $teams[$sport];
?><br /><br />

…and here is the relevant html:

    <select onchange = "getTeams(this.value);">
        <option>
            --select a sport--
        </option>
        <option value = "basketball">
            basketball
        </option>
        <option value = "baseball">
            baseball
        </option>
        <option value = "football">
            football
        </option>
    </select>

    <select id = "teamsList"></select>
  • 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-01T11:04:07+00:00Added an answer on June 1, 2026 at 11:04 am

    It looks like your issue is here:

    return $teams[$sport];
    

    Try

    echo $teams[$sport];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yo. I'm really quite new to this whole JavaScript business, not to mention AJAX,
Hello I'm having the same problem from this post: Ajax.BeginForm not hiding loading element
Why doesn't this simply jQuery ajax code not load pull.php into the div with
I am currently executing AJAX query stores on each onblur if this.value is not
This works great at retrieving the php data for say 15 passes BUT when
I am developing an HTML/Javascript/JQuery page retrieving a JSON returned by a PHP script:
This ajax thing im working on is not doing what i tell it to
This ajax request checks if a TIF file exists in a certain directory and
I'm new to AJAX/javascript, and I'm not sure what the best approach is for
I am retriving this content from ajax <div id=content> click on image to close<img

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.