Skip to content

Instantly share code, notes, and snippets.

@ftherese
Created October 29, 2009 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftherese/221485 to your computer and use it in GitHub Desktop.
Save ftherese/221485 to your computer and use it in GitHub Desktop.
function createRequest() {
var result = null;
if (window.XMLHttpRequest) {
result = new XMLHttpRequest();
if (typeof xmlhttp.overrideMimeType != 'undefined') {
result.overrideMimeType('text/xml'); // Or anything else
}
}
else if (window.ActiveXObject) {
// MSIE
try { result = new ActiveXObject("Microsoft.XMLHTTP");}
catch(err){ try{result = new ActiveXObject("MSXML2.XMLHTTP");}
catch(err){}
}
else {
// No known mechanism -- consider aborting the application
}
return result;
}
for ( i =1; i<=entry.openSearch$totalResults.$t;i+=10) {
var req = createRequest(); // defined above
// Create the callback:
req.onreadystatechange = function() {
if (req.readyState != 4) return; // Not there yet
if (req.status != 200) {
// Handle request failure here...
return;
}
// Request successful, read the response
var resp = req.responseText;
// ... and use it as needed by your app.
}
var link = document.createElement('a');
link.href = '#';
link.onclick = function(){req.open("GET", 'http://books.google.com/books/feeds/volumes?q=' + encodeURIComponent(query) + '&min-viewability=partial' + '&start-index=' + i + '&alt=json-in-script&callback=handleResults', true); return false};
textElem.innerHTML = i + ' ';
link.appendChild(textElem);
document.getElementById("bookBar").appendChild(link);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment