javascript - Ionic Serve- XMLHttpRequest cannot load on Browser -


i writing feature in ionic framework requires communication api. attempt use xmlhttprequest() function majority of resources found online call for, request fails each time, despite fact have internet access, cannot load error.

if makes difference, testing app ionic serve --lab, , through local machine (which connected internet. guess wondering degree proper way communicate restful api through ionic be, well. appreciated.

the problem cors. while in app mobile phone handles cross domain connections in browser no go.

what need setup proxy using ionic.project

{   "name": "appname",   "app_id": "",     "proxies": [     {       "path": "/devapi",       "proxyurl": "https://api.somewebsite.com/api/"     }   ] } 

after every ajax request should sent "/devapi" did not switch every 5 seconds between them in application initlization

if (window.cordova) {   $rootscope.baseurl = 'https://api.somewebsite.com/api/'; } else {   $rootscope.baseurl = 'devapi/'; } 

further reading proxies: http://ionicinaction.com/blog/how-to-fix-cors-issues-revisited/