httprequest - Vue Resource Cross-site HTTP request -
normally, when make jquery request non-local server, applies cross-site http request rules , sends options request verify existence of endpoint , sends request, i.e.
get domain.tld/api/get/user/data/user_id
jquery works fine, use vue resource deal requests. in network log, see actual request being made (no options request initially), , no data being received.
anybody has idea how solve this?
sample code:
var options = { headers: { 'authorization': 'bearer xxx' } }; this.$http.get(config.api.base_url + 'open/cities',[options]) .then(function(response){ console.log('new request'); vm.cities = response; }, function(error){ console.log('error in .js:'); console.log(error); });
solution:
as @anton mentioned, it's not necessary have both requests (environment negligible). not sure have changed make work, request gave me error. consisted in setting headers correctly. headers should not passed options property of http:
this.$http({ root: config.api.base_url + 'open/cities', // url, endpoint method: 'get', headers: { 'authorization': 'bearer xxx' } }).then(function(response){ console.log('new request'); vm.cities = response; }, function(error){ console.log('error in .js:'); console.log(error); });
thank guys, team effort :)
is requirement additional options
request being made? have created small (32 loc) example works fine , retrieves data:
https://jsfiddle.net/ct372m7x/2/
as can see, data being loaded non-local server. example located on jsfiddle.net , request made httpbin.org - leads cors being applied (you can see access-control-allow-origin
header in screenshot below).
what see get
request has been executed, no options
before that.
Comments
Post a Comment