0

I can't find documentation on this anywhere since IE8 is so old. I'm simply trying to use JavaScript to make a Google API call. Something in python would look like this:

    page= urlopen("http://example.com")
    response = page.read()

I found some documentation that said to use XMLHttpRequest. I'm not so sure about the syntax but it would look something like the following:

    var req = new XMLHttpRequest();
    //req.responseType = 'JSON'; to get JSON?
    req.open("GET", url, false);
    req.send();

What would the JS code for an API call look like for something that works in IE8?

Scimonster
  • 32,893
  • 9
  • 77
  • 89
Aaron
  • 11
  • 1

1 Answers1

0

XMLHttpRequest is supported since IE 7

And in case, taht you need to support a browser, that does not know the XMLHttpRequest object, you should use polyfill, which emulates that default API behavior.

A good list is that of the Modernizr project: "HTML5 Cross Browser Polyfills – The No-Nonsense Guide to HTML5 Fallbacks"

I have used the following snippet to have the XMLHttpRequest object provided for different MS IE versions:

if (typeof XMLHttpRequest === 'undefined') {
  /* XMLHttpRequest polyfill */
  var XMLHttpRequest = function () {
    try { return new ActiveXObject( 'Msxml2.XMLHTTP.6.0' ); }
    catch (e) {}
    try { return new ActiveXObject( 'Msxml2.XMLHTTP.3.0' ); }
    catch (e) {}
    try { return new ActiveXObject( 'Microsoft.XMLHTTP' ); }
    catch (e) {}
    throw new Error( 'This browser does not support XMLHttpRequest.' );
  };
}
feeela
  • 29,399
  • 7
  • 59
  • 71
  • Not if I wanted to call a function like send, or response. How would I do it without these functions? – Aaron Jun 23 '14 at 20:20