git.iko.soy/typeable/servant
on master help sign in
Fix 294
a15d1d9Arian van Putten
servant-js/src/Servant/JS/Vanilla.hs+4−1
@@ -37,10 +37,13 @@ generateVanillaJSWith opts req = "\n" <>
37 <> (if isJust (req ^. reqBody) then " xhr.setRequestHeader(\"Content-Type\",\"application/json\");\n" else "")
37 <> (if isJust (req ^. reqBody) then " xhr.setRequestHeader(\"Content-Type\",\"application/json\");\n" else "")
38 <> " xhr.onreadystatechange = function (e) {\n"
38 <> " xhr.onreadystatechange = function (e) {\n"
39 <> " if (xhr.readyState == 4) {\n"
39 <> " if (xhr.readyState == 4) {\n"
40+ <> " if (xhr.status == 204) {\n"
41+ <> " onSuccess();\n"
42+ <> " } else if (xhr.status >= 200 && xhr.status < 300) {\n"
40 <> " var value = JSON.parse(xhr.responseText);\n"
43 <> " var value = JSON.parse(xhr.responseText);\n"
41− <> " if (xhr.status == 200 || xhr.status == 201) {\n"
42 <> " onSuccess(value);\n"
44 <> " onSuccess(value);\n"
43 <> " } else {\n"
45 <> " } else {\n"
46+ <> " var value = JSON.parse(xhr.responseText);\n"
44 <> " onError(value);\n"
47 <> " onError(value);\n"
45 <> " }\n"
48 <> " }\n"
46 <> " }\n"
49 <> " }\n"