0
我認爲下面的問題是範圍相關的,但我不是很好用jQuery插件模式,我該如何解決它?Jquery回調 - 未捕獲ReferenceError
詳細
我試圖修復an issue(跨域)本chrome extension
我想我找到(使用anyorigin.com
)一個解決方案,但我得到了與$.getJSON
一個新的問題:
Uncaught ReferenceError: jQuery19109374020271279013_1462700430014 is not defined:
?url=https%3A//thepiratebay.cr/search/I%20Will%20Survive%201999/0/7/0&callback=jQuery19109374020271…:1 Uncaught ReferenceError: jQuery19109374020271279013_1462700430016 is not defined(anonymous function) @ ?url=https%3A//thepiratebay.cr/search/I%20Will%20Survive%201999/0/7/0&callback=jQuery19109374020271…:1
這裏涉及的代碼doSearch()
是我去問題的地方:
(function($) {
$.fn.extend({
tpbSearch : function(options){
var defaults = { searchTerm: ''};
var options = $.extend(defaults, options);
return this.each(function(){
doSearch($(this), options.searchTerm);
})
}
});
// private functions
// ....
function buildSearchUrl(searchTerm)
{
var searchPart = 'https://thepiratebay.cr/search/' + encodeURIComponent(searchTerm) + '/0/7/0';
var searchUrl = 'http://anyorigin.com/get?url=' + escape(searchPart) + '&callback=?';
return searchUrl;
}
// function where the issue happens.
function doSearch(container, searchTerm){
// here we should iterate over the container selector, because it's possible multiple items will be selected.
var sanitizedSearchTerm = sanitizeSearchTerm(searchTerm);
// set the default logo
var loadingImageUrl = chrome.extension.getURL('images/ajax-loader.gif');
var logo = $('<img id="tpb-logo">')
.attr('src', loadingImageUrl)
.css('width', '25px')
.css('height', '25px');
container.children().remove();
container.append(logo);
var searchUrl = buildSearchUrl(sanitizedSearchTerm);
$.getJSON(searchUrl, function(data){
alert('aa');
});
}
}(jQuery));
我不確定你是否對JSON部分是正確的(相同的命令,在js控制檯的同一頁上工作...)無論如何,你是完全正確的關於CORS和Chrome的分機。這就像一個魅力。 Thx – WonderLand
嗯,該代碼來自內容腳本。那麼問題就是孤立的世界。我更新了答案是正確的。 – Xan