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.

This is my first ever post in Stack Overflow. I am also returning to my programming roots after 16 years. Please pardon me if I am not following appropriate convention. I have been trying for more than a week to get the authentication API from iHealthLabs to work.

I am trying to process HTML that is returned by the iHealthLabs API. I need to process the HTML to make the links clickable when the page is launched from the ngCordova InAppBrowser plugin (which is otherwise turned to plain text, I believe due to $sanitize). I am using Angular's $http.

In order for $http to not process the response as JSON, I have set the transformResponse option to [] as below:

var req = {
  url: "http://sandboxapi.ihealthlabs.com/OpenApiV2/OAuthv2/userauthorization/?callback=JSON_CALLBACK&client_id=d9bc6644db6f4acfbf64748bac4782a1&response_type=code&redirect_uri=http://localhost:8100/ihealthdata?userid=john&APIName=OpenApiBP&RequiredAPIName=OpenApiBG+OpenApiBP&IsNew=true",
  method: 'jsonp',
  cache: false,
  transformResponse: []
};

Here is the request:

$http(req).
success(function(data, status, headers, config) {
  $scope.html = data;

}).
error(function(data, status, headers, config) {

});

However, I get the following error: Uncaught SyntaxError: Unexpected token <

I was wondering if there is something obvious I am missing or if I have to use the Angular Interceptors to trap the response and go from there.

Thank you for your help.

share|improve this question
    
I suspect this in a simple syntax error with the example code above. Can you try changing your request from $http(req). to $http.get(req). and let me know if you get the same error? –  sal niro yesterday
    
@sal niro I tried this, but it gave me other errors. I believe the syntax is fine. Specifying $http.get or $http(config) where var config = { {method:'GET'} } creates the same object. Since the call is from a browser, it has to be JSONP otherwise I get the Access-Control-Allow-Origin error. So to follow your suggestion instead of $http.get , I used $http.json(req) with the same result. I am getting the HTML back, but I think AngularJS is trying to process it as Javascript instead of HTML. Not sure if there is a way to tell AngularJS that the response is HTML. –  increos 15 hours ago

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.