Skip to content

How to use DuckDuckGo’s search autocomplete suggestions

I’m transitioning my personal search suggestions from google to duckduckgo, but I’m missing something simple to make it work. I’m using jQuery-UI’s autocomplete framework.

My search form

<form action="" method="post" id="search">
    <input type="text" name="query" value="" autocomplete="off">
    <button type="submit">Search</button>

My jQuery

$( "#search input[type=text]" ).autocomplete(
    delay: 0,
    minLength: 1,
    position: { my: "left top-3" },
    source: function( request, response )
     // var suggestURL = "";
        var suggestURL = "";
        suggestURL = suggestURL.replace( "%QUERY", request.term );
            method: "GET",
            dataType: "jsonp",
            jsonpCallback: "jsonCallback",
            url: suggestURL,
            success: function( data )
                response( data[1] );
            error: function( jqXHR, textStatus, errorThrown )
                console.log( textStatus, errorThrown );

The query for google returns:
jsonCallback && jsonCallback(["foobar",["foobar","foobar meaning","foobar google","foobar challenge","foobar2000 skins","foobar2k","foobar2000 themes","foobar2000 download","foobar2000 mac","foobar themes"],[],{"google:suggestsubtypes":[[433],[],[],[],[],[],[],[],[],[]]}])

The query for duckduckgo returns:
["foobar",["foobar2000","foobar","foobar2000 download","foobar ape","foobar2000 layout","foobar2000 decoder","foobar2000 tak","foobar2000 dsp"]]

The difference between the two seems to be jsonCallback && jsonCallback([data]) is included in the google query and I don’t understand why they’re different or how to fix it.


After adding some error handling to the js, the error I’m getting is:

parsererror Error: jsonCallback was not called


After digging into this a bit more, I don’t think DDG’s server allows it. It’s my understanding that their server needs to send an appropriate response and I don’t think it’s doing so.


Please see:

To consume it yourself, you can use one of the language libraries listed below or simply add ‘&format=json’ (or xml if you prefer) onto any query URL in the api subdomain, e.g.

Here are the requirements for use:

  • Attribution in each place you use our API for both us and any underlying source. For the source, you can link to the source’s relevant detail page. For us, you can say Results from DuckDuckGo with our logo (and link to the specific result page).
  • Non-commercial use unless you get email approval from us (though we’re generally fine with anything that isn’t sketchy).
  • Use a descriptive t parameter, i.e. append &t=nameofapp to your requests.

Our overall goal is to get more people using DuckDuckGo, so please keep that in mind as well.

q: query
format: output format (json or xml)
If format=='json', you can also pass:
callback: function to callback (JSONP format)

This works successfully with JSONP:

The problem here is that these are not suggestions and the URL for those, does not want to play nice with CORS. You can fudge around it with FETCH API yet this just proceed with the Promise even if the request fails or can’t be parsed.

So until DDG offers a Suggestion API, you’re mostly out of luck.

Some potential other options are discussed here:

var script = $("<script />", {
    src: "" + req.term,
    type: "application/json"

Although that works, it doesn’t help us much, as we have no way of getting at the data it contains.


The browser shows the response but then you get a Parse Error.