Note that there are some explanatory texts on larger screens.

plurals
  1. POAny way to simulate a *synchronous* XDomainRequest (XDR) request
    primarykey
    data
    text
    <p>We're making a cross domain call to the google maps geocode API. This was and is working all fine and dandy in modern browsers, but it wasn't working at all in IE8. Looks like it would fail in IE9 as well (partial CORS support). This led to including a XDomainRequest (XDR) to take care of IE8-9. Doing that worked fine in my standalone test to get data back in IE8.</p> <p>The problem I'm running into now is XDR only works asynchronously so my geocode function returns before my xdr.onload fires.</p> <p>In my search function, I call the geocode function:</p> <pre><code>var location = Geocode(city, state); if (!location) { alert('Unable to determine the location of the city and state you entered'); StopLoading(); return; } //function then uses location.lat and location.lng coordinates </code></pre> <p>I'm hitting the "Unable to determine location" alert above in IE8.</p> <p>Here's my geocode function:</p> <pre><code>Geocode = function (address, state) { var protocol = location.protocol, url = '//maps.googleapis.com/maps/api/geocode/json?sensor=false&amp;address=', param = encodeURIComponent(address + ', ' + state), json = {}; if ('XDomainRequest' in window &amp;&amp; window.XDomainRequest !== null) { //IEs that do not support cross domain xhr requests var xdr = new XDomainRequest(); xdr.open('get', protocol + url + param); xdr.onload = function() { json = jQuery.parseJSON(xdr.responseText); }; xdr.send(); } else { //good browsers jQuery.ajax({ url: protocol + url + param, type: 'get', dataType: 'json', async: false, success: function(data) { json = data; } }); } //alert(json); if (json.status !== 'OK') { alert('Unable to determine the location of the city and state you entered'); return null; } return json.results[0].geometry.location; }; </code></pre> <p>If I comment out the alert(json) in the geocode function, I get my results in IE8 because that's a blocking operation so the request has time to finish and populates my json object. When it's run uncommented, the json object isn't populated.</p> <p>Anyone have any ideas how I can get this working in IE?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload