Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to use data from a JSON file in a different domain to integrate on an app using Html and AngularJS and I'm not sure how to do this. I'm having trouble fetching the data from the other domain due to the same-origin policy. The functionality of this app is to search for available phone numbers, through an API I received from a third-party. This is the schema of what I would like to achieve:

  1. Html file with Form - the user will provide the desired area code and a short 'phrase' (up to 4 chars) which will be a part of the phone number
  2. GET request to the external service provider will be made, using the data the user entered as parameters. The service sits on https, and requires basic authentication. The structure is something like this: https://www.serviceprovider.com/username/phonenumbers?areacode={{areacode}}&phrase={{phrase}}

    so if the user enters in the form area code: 212 and phrase SHOP, the GET request will be made to: https://www.serviceprovider.com/username/phonenumbers?areacode=212&phrase=SHOP Using basic auth. The response of this request is a JSON which contains the numbers:

    [{phonenumber: '212-555-7467', phrasenumber: '212-555-SHOP'}, {phonenumber:'212'557-4675', phrasenumber: '212 55SHOP5}]

  3. These numbers will be displayed to the user

Right now, things are stuck on step (2) - when trying to make the GET request through the JS/JQuery, I get the Origin is not allowed by Access-Control-Allow-Origin error. I do not have access to the server which holds the JSON, it's a third party and thus any changes in set-up there are out of my scope.

What is the best way to achieve what I am after? Is there any way that I can make the request in a non-browser environment (thus avoiding the error) and temporarily create a copy of the JSON in my own domain, making it accessible for me?

share|improve this question

1 Answer 1

The steps taken here are different depending on your server setup. You have to ensure that whatever server you are using accepts your client application's origin. Here is a good write up on CORS:

https://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity

share|improve this answer
    
They don't support CORS. Is there any way that I can work around it without any modification from their end? I have no trouble fetching the JSon data when making the request in non-browser environment (i used python to test) –  user3836205 Sep 29 '14 at 15:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.