简体   繁体   中英

Error applying suggestionCallback in a closure

chrome.omnibox.onInputChanged.addListener(function(text, suggestionsCallback){
    ....
    $.get(url_base + text, function(data){
        ....
        suggestionsCallback(suggest_results);

In my callback closure "suggestionCallback" takes no effect. But if I put this callback line outside of the closure, the line just works fine.

Is this a bug of Chrome? Or, did I miss-understand something?

I have no knowledge of jquery and am just horrid with details, so I cant explain to you why it doesnt work. But in my tests I noticed that doing it in a none jquery way works, so try something like this....

chrome.omnibox.onInputChanged.addListener(
function(text, suggest) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url_base + text, true);
    xhr.onload = function(e) {
        if (this.status == 200) {
            suggest(suggest_results);
        } else {
            //error, not found or something
            console.debug('Im bugging out man!');
        }
    }
    xhr.send();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM