vendredi 15 décembre 2017

Google Auto Complete CORS issue when called from ember

I am trying to call google api making a ajax call like below:

fetch(){
let url=`http://ift.tt/2yqGGB3`
return Ember.RSVP.resolve(Ember.$.ajax(url,{
method: 'GET'
}))
.then(
(response)=>{
console.log("google suggested places:",response);
return response;
})

But i am getting " Failed to load http://ift.tt/2yqGGB3: No 'Access-control-Allow_origin'header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

I tried many options like below: in app/services/service.js dataType: 'jsonp' jsonp: "json_callback", jsonp : "callback", jasonpCallback: 'jsonpcallback' cache: false/'false'

but none of them resolved my issue.

Also i tried the following: in app/services/service.js

var restRequest = gapi.client.request({
'path': 'http://ift.tt/2kvO1L3'
});

var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://ift.tt/2kvO1L3');

and I did the following to install gapi-client: npm install --save gapi-client and have this in my service.js

import gapi from 'gapi-client'

but i get an error in console " could not find module ' gapi-client' imported from 'projectname/services/servicename'

What is that i am doing wrong or am i missing anything?

A old thread to this is below: response undefined when calling google api thru emberjs




Aucun commentaire:

Enregistrer un commentaire