K
K
Kanonier82015-07-03 19:49:42
JavaScript
Kanonier8, 2015-07-03 19:49:42

How to remake ajax request using jsonp?

There is an AJAX request that doesn't work in IE . I so believe that a problem in request. In this regard, I decided that jsonp can be used . This is where my ideas run out and I feel helpless in trying to deal with it. Maybe someone will tell?

$.ajax({
          url: 'http://maps.googleapis.com/maps/api/geocode/json?address='+address,
          dataType: 'json',
          type: 'GET',
          success: function(response){
            if(response.results.length) {
              responseCoords=new google.maps.LatLng(response.results[0].geometry.location.lat, response.results[0].geometry.location.lng);
              calcRoute(responseCoords);
            }
          }
        });

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
Hoota, 2015-07-06
@hoota

Use the Google-Api library, don't pull their json directly.
Your example will look like this:
1) Connect their library
2) pull their API through their library

<script type="text/javascript">     
   var geocoder = new google.maps.Geocoder();
   var address = 'London, UK';

   if (geocoder) {
      geocoder.geocode({ 'address': address }, function (response, status) {
         if (status == google.maps.GeocoderStatus.OK) {
             responseCoords = new google.maps.LatLng(response.results[0].geometry.location.lat, response.results[0].geometry.location.lng);
              calcRoute(responseCoords);
         }
      });
   }    
</script>

E
Evgeny Lebedev, 2015-07-03
@HollowJ

https://learn.jquery.com/ajax/working-with-jsonp/

A
Alexander, 2015-07-04
@liff

dataType: "jsonp"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question