The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery autocomplete from a text file…

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #34414

    I think I am at the end with my autocomplete adventures, it seems to have beaten me :(

    I’ve successfully set it up so it reads data from an XML file. However, the XML file is about 1.2mb big and this was causing the site to load very slowly.

    I would go down the JSON route…but it says you need to create a PHP file, which creates the JSON? But that’s it, no demo, doesn’t tell you what goes in the PHP file at all. It just assumes you know how to work with JSON, which I don’t. It also seems overly complex…

    So my idea is that I read the data from a txt file instead.

    The data looks like this:

    Goroka,Goroka,Papua New Guinea,GKA,AYGA
    Madang,Madang,Papua New Guinea,MAG,AYMD
    Mount Hagen,Mount Hagen,Papua New Guinea,HGU,AYMH
    Nadzab,Nadzab,Papua New Guinea,LAE,AYNZ
    Port Moresby Jacksons Intl,Port Moresby,Papua New Guinea,POM,AYPY
    Wewak Intl,Wewak,Papua New Guinea,WWK,AYWK

    That is only a tiny sample, there are actually 8000 airports in this file so using an array is not an option.

    Is there no way I can just call in that data?

    Or, if I have to use JSON, please can somebody help me find out what needs to go in to the PHP file that autocomplete uses? I’ve got my data in JSON format (I think) I just don’t know what goes in the PHP and nowhere tells me :(

    So frustrating…


    My javascript:

    	$(function() {

    $( "#from" ).autocomplete({
    source: "",
    minLength: 2,

    My PHP:

    header('Content-Type: text/plain');
    $fileAsArray = Array();

    if (($handle = fopen("airports.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $fileAsArray[] = $data;



    Doesn’t quite work. The autocomplete box shows up when you type – just with nothing in it, so it’s just like a line.



    No ideas? :(


    First, you’ll need to find whether the problem is with the data your PHP script is providing or with your Autocomplete plugin setup.

    Do you have some sample data from the PHP script when you run it in a browser/firebug? I’m not familiar with the Autocomplete plugin, but make sure the data matches what it expects to be given.

    If that’s not the issue, check the plugin’s documentation and make sure you’re using the right options.

    If you’re still lost, simplify the problem to its most basic components and try reposting to the forum.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.