<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript" language="javascript">
$.ajax({
type: "GET",
cache: false,
url: 'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=school',
contentType: "application/json; charset=utf-8",
success: function(msg) {
alert(""+msg.length);
},
error: function (e) {
alert("Failed to Get declassification details");
}});
</script>
</body>
</html>
I am not able to figure out whats going wrong with this AJAX call.WENT Through several SIMILAR
question on this forum, but none was working for me.
I have to Get the resultset from Google search in JSON format.
The browser is dropping the request because of cross domain security policy. Try using JSONP (dataType: "jsonp"). Ajax requests to third party websites are normally not possible because of security restrictions. But there are several client-side techniques to work around this restrictions and one of them is JSONP. One thing you will not get from JSONP is notification of network errors or anything that responds nicely to badly formed responses, so you have to accept that as a tradeoff with the ability to invoke services on other domains.
Why and how JSONP works:
See the difference in the response: http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=school
vs