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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:32:06+00:00 2026-06-07T09:32:06+00:00

All, I’ve got the following code to which is basically a function that loads

  • 0

All,
I’ve got the following code to which is basically a function that loads some search terms in it when the DOM is loading:

window.myAutocompleteFunction = function(){
return ['Test Saying','sit amet consectetur adipiscing','elit Nulla et justo'];
};

This works fine for my live search and updates correctly. I’m trying to populate these values based on some information from my database though. I tried to update my code to use a .get function to populate my return values and I tried to make it look like this:

window.myAutocompleteFunction = function(){
$.get('http://localhost/website/load_users.php', function(data) {
    alert(data);
    return [data];
});
};

It tries to load the users and in my alert it is the same as when it’s manually typed in but for some reason when I do the search it doesn’t work. Any idea how to get the same results from my file and have the search work the same?

EDIT: The only thing in my load_users.php file right now is the following:

'Test Saying','sit amet consectetur adipiscing','elit Nulla et justo'

I’m going to try and populate that with database values but just trying to get this to work for now.

Another Edit: I also tried to make my code like the following just to see if it work work:

window.myAutocompleteFunction = function(){
jQuery.get('http://localhost/okyne/load_users.php', function(data) {
    alert(data);
    return ['Test Saying','sit amet consectetur adipiscing','elit Nulla et justo'];
});
};

This doesn’t work either so I’m not sure why it wouldn’t work and the only thing that works for me so far is the first code snippet that I provided.

Any help you can provide is greatly appreciated!

  • 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-07T09:32:09+00:00Added an answer on June 7, 2026 at 9:32 am

    Your $.get can’t return a value like that, because it runs asynchronously and the browser starts evaluating it, moves on and finishes with that fn. before it completes. Also, that particular return will target the inner success-callback function, not the autocomplete function. You will have to load the data and create that function in the success callback.

    Here is a mockup example. http://jsfiddle.net/Nf2UD/

    Note I used setTimeout to make sure the ajax call was finished, but you will want to ensure you call randomFn during your page initialization, to ensure it has run before you try and use autocomplete. You can check this in a couple ways — having a global variable to track the status, checking if the autocomplete function is undefined, …. In truth this isn’t really the point of asynchronous methods, but whatever works for you I guess.

    function() randomFn {
        $.get('http://localhost/website/load_users.php', function(data) {
            alert(data);
            window.myAutocompleteFunction = function(){ return [data]; };
        });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, Say I have the following bit of code: select: function(start, end, allDay) {
All, See the code below: function menu() { this.menuitem=[]; this.submenu=[]; this.menuitem[0] = $('div#sivname1'); this.menuitem[1]
All, I have some script tags that are not working in Wordpress. If I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
All, I have the following code: $fetch = mysql_query(SELECT * FROM calendar_events where event_status='booked'
All the code/commands below are part of a PHP script that processes images from
All, I'm going to use a QR code from the following URL: http://qrcode.kaywa.com/ I
All, If I run a query like the following: $qry = Select wrong_column from
All, If I've go the following database fields/values: user_id field_name field_value 1 EventHour1 1
All I want to do is return the index of the i that is

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.