Base solution for your next web application
Open Closed

Issue with XSRF Token #1991


User avatar
0
maharatha created

I am trying to access the google API from the client side and below is the error I am getting :

XMLHttpRequest cannot load <a class="postlink" href="http://maps.googleapis.com/maps/api/geocode/json?address=4566">http://maps.googleapis.com/maps/api/geo ... dress=4566</a>. Request header field X-XSRF-TOKEN is not allowed by Access-Control-Allow-Headers in preflight response.

Please advise.


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I'm not sure this is related to AspNet Zero but can you share how do you make a request to <a class="postlink" href="http://maps.googleapis.com">http://maps.googleapis.com</a> ?

  • User Avatar
    0
    maharatha created
    if (zip.trim().length > 2) {
                   $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address=' + zip).success(function (response) {
                       var city = [],
                           state = [],
                           country = [];
                       //find the city , state and country
                       if (response.results[0]) {
                           var address_components = response.results[0].address_components;
                           Ext.each(address_components, function (component) {
                               var types = component.types;
                               Ext.each(types, function (type) {
                                   if (type == 'locality') {
                                       cityField.setValue(component.long_name);
                                   }
                                   if (type == 'administrative_area_level_1') {
                                       state.push({ name: component.long_name, state: component.short_name });
                                   }
                                   if (type == 'country') {
                                       country.push({ name: component.long_name, country: component.short_name });
                                   }
    
                               });
                           });
                           if (stateCombo && state.length > 0) {
                               var stateRecord = stateCombo.getStore().findRecord('state', state[0].state);
                               if (stateRecord) {
                                   stateCombo.select(stateRecord);
                               }
                               else {
                                   stateCombo.reset();
                               }
                           }
                           if (countryCombo && country.length > 0) {
                               var countryRecord = countryCombo.getStore().findRecord('country', country[0].country);
                               if (countryRecord) {
                                   countryCombo.select(countryRecord);
                               }
                               else {
                                   countryCombo.reset();
                               }
                           }
                       }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I'm not sure if google allows this kind of request to it's map API. As I said, this is not related to AspNet Zero, you can check google maps javascript api for more information. <a class="postlink" href="https://developers.google.com/maps/documentation/javascript/">https://developers.google.com/maps/docu ... avascript/</a>