下面是我的代码。第一个getGoogleNews()函数未触发
document.onreadystatechange = function () {
if (document.readyState == "complete") {
getGoogleNews("#{@lead.full_name} + #{@lead.company}", 'person_results');
getGoogleNews("#{@lead.company}", 'company_results');
}
}
function getGoogleNews(text, div_id){
function gcseCallback() {
console.log(document.readyState);
if (document.readyState != 'complete')
return google.setOnLoadCallback(gcseCallback, true);
google.search.cse.element.render({gname:'gsearch', div: div_id, tag:'searchresults-only', attributes:{linkTarget:''}});
var element = google.search.cse.element.getElement('gsearch');
element.execute(text);
$("#"+div_id).find('.loader-section').hide();
};
window.__gcse = {
parsetags: 'explicit',
callback: gcseCallback
};
(function() {
var cx = '001443335100840105093:b2rosvfeghy';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
}