Strange behaviour of response when it isn't json in angularjs get

303 Views Asked by At

I have problem with error in angularjs:

Error: [$http:baddata] Data must be a valid JSON object. Received: 'test string test string' Parse error: "{}"

So if I understand it correctly, the response from the server hasn't good JSON format. Let's say that I can't change it on the server side and I try to repair it on the frontend.

So I try to use transformResponse:

function testFunc() {
    return $http.get('url', {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json'
        },
        transformResponse: function(data) 
            return {'status': data} 
        }
    })
}

And then, ok, I haven't errors and everything looks fine but I expected in response something like that: {"status": "test string test string"}

But instead, I have html code from whole my site ({"status": '<HTML>....'}) Why data isn't this string which was when it was the error? How can I deal with it?

0

There are 0 best solutions below