[英]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.在我的回调闭包中,“suggestionCallback”无效。 But if I put this callback line outside of the closure, the line just works fine.
但是如果我把这个回调线放在闭包之外,这条线就可以正常工作。
Is this a bug of Chrome?这是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.我不了解 jquery 并且对细节感到厌恶,所以我无法向您解释为什么它不起作用。 But in my tests I noticed that doing it in a none jquery way works, so try something like this....
但在我的测试中,我注意到以 none jquery 方式进行操作是可行的,所以尝试这样的事情......
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();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.