0

I have the following problem: I am trying to get data from the googlemaps api v3 via ajax with the code below. It works fine in Chrome and Firefox, but not in IE. What am I doing wrong?

var lat;
$.ajax({
url: "url",
cache: false,
dataType: "json",
success: function(data) {      
lat = data.results[0].geometry.location.lat;
}                                                                                                   
});
user1889382
  • 381
  • 1
  • 2
  • 8
  • Please add the error message you get from IE aswell as what version this is happening in. – am_ Feb 23 '13 at 18:28

1 Answers1

0

Add the following error event to your Ajax call

  success: function(data) {
     lat = data.results[0].geometry.location.lat;
    },
   error: function(xhr, status, error) {
     alert(status);
   }

And let us know what error message you get in IE, if any at all.

EDIT - Sounds like you are trying to do a cross-domain request? If that is the case, try setting $.support.cors = true; before your ajax request.

Fetched from http://api.jquery.com/jQuery.support/

To enable cross-domain requests in environments that do not support cors yet but do allow cross-domain XHR requests (windows gadget, etc), set $.support.cors = true;

EDIT2 - Ill assume you are running IE9, in that case you need a plugin for jQuery found here: https://github.com/jaubourg/ajaxHooks/blob/master/src/xdr.js

Also see this answer on SO for more details on why a plugin is needed for IE9 (with cors): IE9 jQuery AJAX with CORS returns "Access is denied"

EDIT3 - Download jQuery.XDomainRequest.js and include it before your AJAX call.

Community
  • 1
  • 1
am_
  • 2,378
  • 1
  • 21
  • 28
  • Thanks for your help. The error I'm getting is "No Transport". – user1889382 Feb 23 '13 at 19:21
  • I added $.support.cors = true; Now I get a new error: "Access denied". I really don't understand this, it still works well with both Chrome and FF. – user1889382 Feb 23 '13 at 22:09
  • Did you read the links i posted above? You need the posted plugin to make it work in IE9. – am_ Feb 25 '13 at 22:40
  • Just saw it. Looks very complicated, it seems this goes well beyond my understanding. Can you tell me how to use the plugin? where do I put this code? Thanks a lot! – user1889382 Feb 26 '13 at 11:19