SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Hybrid View

  1. #1
    SitePoint Enthusiast mitsy's Avatar
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question jquery autocomplete with remote datasource with cache

    i'm using jquery autocomplete function with remote datasource with caching. But i can only work it with a local source php file. if i put the php on another domain, autocomplete script stops working.
    i have spent many hours for googling and trying, but no luck

    my autocomplete jquery is just the same at jqueryui.com:

    Code:
    $(function() {
        var cache = {},
            lastXhr;
        $( "#searchbox" ).autocomplete({
            minLength: 2,
            source: function( request, response ) {
                var term = request.term;
                if ( term in cache ) {
                    response( cache[ term ] );
                    return;
                }
                lastXhr = $.getJSON( "http://example.com/source.php", request, function( data, status, xhr ) {
                    cache[ term ] = data;
                    if ( xhr === lastXhr ) {
                        response( data );
                    }
                });
            }
        });
    });


    and an example output of source php file is:

    ["bird","cat","dog","fox"]


    i know i need to put ?callback=? to the source url and echo $_GET['callback'] to the php file but i couldn't make it work! how can i achive remote domain autocomplete with caching? there is no answer of this question around and this will help many people i think.
    please tell me what to do in php and jquery?
    Last edited by paul_wilkins; Mar 25, 2012 at 22:38. Reason: removed offer of money, the marketplace is the place for that


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •