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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:49:55+00:00 2026-06-06T20:49:55+00:00

I am attempting to be able to dynamically reload the variable I’m going to

  • 0

I am attempting to be able to dynamically reload the variable I’m going to be using for an auto complete field, but I’m having trouble loading the initial call. Presently, my javascript consists of this:

<script type="text/javascript">
  var myList;

  function setTextSuggest() {
    $("#loginInput").autocomplete({
      source: myList,
      appendTo: "#loginDiv"
    });
  };

  $(document).ready(function() {
    $.getJSON('StarWars.php', function(data) {
      myList = JSON.parse(data);
      //alert(myList); //DOES NOTHING WHEN UNCOMMENTED!!!!
      setTextSuggest();
    });
  });
</script>

When I replace myList in the alert with ‘data[“info”]’, it spits out the JSON info I’m expecting. However, if I were to uncomment the alert and run it on myList, nothing at all would print. myList is supposed to have global scope here, but I can’t figure out why it’s not assigning inside my readied function.

Does anyone have any suggestions on how to resolve this issue?

EDIT:

The following is the object being returned from StarWars.php (created via json_encode):

{"UserList":["Han Solo","Leia Organa","Luke Skywalker","Darth Vader","Emperor Palpatine","Chewbacca","R2-D2","C-3PO","Lando Calrissian","Lobot","Yoda","Obi-Wan Kenobi","Uncle Owen","Aunt Beru","Wedge Antilles","Boba Fett"]}

If I set the getJSON request as:

$.getJSON('StarWars.php', function(data) {
    myList = data.UserList;
    alert(myList);
    setTextSuggest();
});

Then it shows me the list of names, but I still have nothing set in my autocomplete.

Edit 2:

I have accepted Jack’s answer for this question. While my code does still have issues (autocomplete is not appending yet), Jack’s solution has moved it out of the realm of a question on global variables and JSON data retrieval and into a question about using the jQuery 1.8 autocomplete correctly. I feel this is a different question, so I’m marking this issue as complete. -D.G.

  • 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-06T20:49:58+00:00Added an answer on June 6, 2026 at 8:49 pm

    Judging from your question, data is already a proper array / object (not text), so you don’t need JSON.parse() at all.

    Just this should do:

    myList = data;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to dynamically access both the $_GET and $_POST arrays, among others, using
I'm attempting to run a parallel job in R using snow. I've been able
I am attempting to create a form where a user is able to enter
I am attempting to create a table in rails.. I need to be able
I'm attempting to create a postcode lookup JQuery script that'll be able to be
Attempting to set up Samba + OpenLDAP using nss_ldap. After joining Windows7 to Samba
I'm attempting to create themeing system for my asp.net mvc application. I was able
I'm attempting to learn Spring MVC but have been spoiled by Grails. While I
When attempting a file upload to an Alfresco Server using ssl the server logs
I'm able to ping the remote server I am attempting to connect to successfully.

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.