javascript - Angular - How to work with HTTPS using $http -


just wanted ask on how deal https + cross-domain url using $http?

i've used $.ajax solve problem, reason why wanted use $http more because have $http interceptor since using $.ajax takes lot more line of codes rather having interceptor automate process.

i've read similar posts [link1, link2, link3] neither of them have solved problem.

i have attached screenshot of console, hope makes sense: http-ajax.

the weird thing option method being used $http have set post

here's code snapshot:

$http({     method: 'post',     url: '/hearingcentre',     data: {         type: ['p', 'v']     },     success: function (res) {         console.log(res);         d.resolve(res);     },     error: function (res) {         console.log(res);         d.reject(res);     }  }); 

note: i'm using $http interceptor here url appended base api url

$.ajax version

$.ajax({     method: 'post',     crossdomain: true,     url: 'https://ahtstest.hearing.com.au/services/api/hearingcentre',     data: {         type: ['p', 'v']     },     success: function (res) {         console.log(res);     },     error: function (res) {         console.log(res);     } }); 

do have solution this?

var userapp = angular.module('userapp', []);     userapp.controller('usercontroller', function ($scope,$http) {          //server call angular          $scope.makeservercall = function() {                 var url = '/root/jsp/catalog/xml/getjsp.jsp?patientid=9175;                 $http({                     crossdomain: true,                     xhrfields: {withcredentials: false},                     headers: {'accept': 'application/json','content-type': 'application/json'},                     method: 'get',                     url: url                 }).then(function(response) {                     console.log("success: "+json.stringify(response));                 },function(response) {                     console.log("error:   "+json.stringify(response));                 });         };   } 

and make sure @ server side can accessible cross domain reuqest. lets using spring mvc have added 1 filter , configure cross domain request allow follow. if using other language lets php, have set response header.you can search same.

my server filter spring mvc

@component public class ecwcorsfilter implements filter {          public void dofilter(servletrequest req, servletresponse res, filterchain chain) throws ioexception, servletexception {                 httpservletresponse response = (httpservletresponse) res;                 response.setheader("access-control-allow-origin", "*");                 response.setheader("access-control-allow-methods", "post, get, options, delete");                 response.setheader("access-control-max-age", "3600");                 response.setheader("access-control-allow-headers", "content-type, authorization, x-requested-with,isajaxrequest");                 chain.dofilter(req, res);         }          public void init(filterconfig filterconfig) {         }          public void destroy() {         }  } 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -