XhrRequest with reflex/reflex-dom

放肆的年华 提交于 2019-12-04 04:21:55

With help from #reflex-frp on freenode I found a solution: replacing decodeXhrResponse with _xhrResponse_body and using Text for the default string worked:

buttonDyn <- holdDyn (Just $ T.pack "default") $ fmap _xhrResponse_body asyncEvent

decodeXhrResponse expects some sort of JSON and although I tried to serve JSON via Scotty at one point it still didn't work.

I wrote this simplified helper function to basically retrieve a remote URL from reflex:

curlGet :: MonadWidget t m => Text -> m (Event t Text)
curlGet url = do
  let req = xhrRequest "GET" url def
  pb <- getPostBuild
  asyncReq <- performRequestAsync (tag (constant req) pb)
  pure $ fmap (fromMaybe "Unknown error" . _xhrResponse_responseText) asyncReq
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!