@@ -18,6 +18,7 @@ module Network.HTTP.Affjax
1818
1919import Prelude
2020
21+ import Control.Bind ((<=<))
2122import Control.Monad.Aff (Aff (), makeAff , makeAff' , Canceler (..), attempt , later' , forkAff , cancel )
2223import Control.Monad.Aff.AVar (AVAR (), makeVar , takeVar , putVar )
2324import Control.Monad.Eff (Eff ())
@@ -28,7 +29,7 @@ import Control.Monad.Error.Class (throwError)
2829
2930import Data.Array as Arr
3031import Data.Either (Either (..), either )
31- import Data.Foreign (Foreign ())
32+ import Data.Foreign (Foreign (), F (), parseJSON , readString )
3233import Data.Foldable (any )
3334import Data.Function (Fn5 (), runFn5 , Fn4 (), runFn4 , on )
3435import Data.Int (toNumber , round )
@@ -239,10 +240,15 @@ affjax' req eb cb =
239240 _ -> hs
240241
241242 cb' :: AffjaxResponse ResponseContent -> Eff (ajax :: AJAX | e ) Unit
242- cb' res = case res { response = _ } <$> fromResponse res .response of
243+ cb' res = case res { response = _ } <$> fromResponse' res .response of
243244 Left err -> eb $ error (show err )
244245 Right res' -> cb res'
245246
247+ fromResponse' :: ResponseContent -> F b
248+ fromResponse' = case snd responseSettings of
249+ JSONResponse -> fromResponse <= < parseJSON <= < readString
250+ _ -> fromResponse
251+
246252type AjaxRequest =
247253 { method :: String
248254 , url :: URL
0 commit comments