i am using google search JSAPI in my local search app. Everything works fine in all the browsers except IE 8. The problem is after the specific line of code my jquery base o
Change your jsFiddle to "No wrap (body)" and modify your function like so...
//$(function() {
//alert(1);
google.load('search',1);
alert($);
google.setOnLoadCallback(function() {
alert(2);
});
//});
Nearly the same question asked here: Google is not defined using Google Visualization API; possibly jQuery's fault
This problem is caused by document.write
in Google's load
API, similar to this question. The script is deferred, as seen in the picture below:
To solve the issue, do not wrap the code in an onload/domready handler.
<script src="http://www.google.com/jsapi?" type="text/javascript"></script>
<script>
// All load-related invocations have to be placed here.
google.load('search',1);
google.setOnLoadCallback(function() {
alert(2);
});
</script>
Note that JSfiddle places any content at the upperleft corner within the <body>
tags. So, a simple copy-paste of the code in JSFiddle will not show the right results.
I have faced the same issues.Here's the resolution.
If you want to use google visualization api in JQuery. Please follow the below approach
<script type="text/javascript">
//Load the Google visualization library
google.load("visualization", "1.1", {packages:["bar"]});
$(document).ready(function() {
google.setOnLoadCallback(function () {
$('#Search').click(sendAndDraw);
});
$("#Search").click(function (e) {
var data = google.visualization.arrayToDataTable([
['Technology', 'Beginner', 'Intermediate', 'Expert'],
['Java', 10, 40, 20],
['DOT NET', 11, 46, 25],
['Mainframe', 66, 11, 30],
['Oracle', 10, 50, 30]
]);
var options = {
chart: {
title: 'Management Reports',
subtitle: 'Classification of resources',
}
};
var chart = new google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, options);
});