Preventing JSON parsing in angular $http get

Viewed 512

I have some jquery code that looks like this:

    $.ajax({
       type        : 'POST',
       url         : 'http://unfurl.oroboro.com/unfurl',
       data        : formData,
       dataType    : 'json',
       converters  : {
                        "* text": window.String, 
                        "text html": true, 
                        "text json": window.String, 
                        "text xml": window.String
                     },
       success     : function(data) 
                     {
                        jdata = jQuery.parseJSON( data );
                     }
    });

Note that I set converters for json to string. I do this because I want to prevent JQuery from automatically parsing the string into JSON because it will also html encode the strings which causes problems. The strings already come correctly encoded from the service.

The code above works great.

Now I want to do something similar in Angular with http get:

        var unfurlUrl = "http://unfurl.oroboro.com/unfurl?url=" +
                        encodeURIComponent( $scope.url );
        $http.get( unfurlUrl, 
            {
                converters : {
                    "* text": window.String, 
                    "text html": true, 
                    "text json": window.String, 
                    "text xml": window.String
                }

            }).then( function( response ) {

                jres = jQuery.parseJSON( response );
            });

But this does not work. Angular continues html encode the data and then JSON parse it.

Some questions:

  1. How to get Angular to just give me the raw data so I can deal with it.
  2. Is there are way to just tell it not to html encode this? Or do I have to do like JQuery turn off all processing and then do this myself?

If you want to see the data that comes from my service, there is a form there that will show raw output:

http://unfurl.oroboro.com

@update: As per GeorgeAwg's link, the following is how you do this:

$http.get( unfurlUrl, {transformResponse: undefined }).then

Charlietfl: actually you're right. The extran html encoding happens not in the json parsing, but in an assignment later.

0 Answers
Related