XHR doesn't work with API #806
-
Bug ReportI found a condition where API calls don't work properly, but I'm not sure if I can explain it properly. Here goes: The issue is related to basic authentication and unauthorized responses. Note that this issue is occurring because I'm trying to verify logins by sending an API call to the REST API by setting the username and password in the Basic Authentication header. The issue doesn't seem to be caused by the REST API or the CORS settings. API calls get aborted every time and even though the response is a 200 with a JSON object, FUI API is not aware of this and always returns These calls get aborted:
Jquery alternative that also fails:
jQuery alternative that works, because it seems handle 401 responses differently? It's also aware of the response object:
Expected resultI'm expecting a Actual result
TestcaseNot possible due to rest api running locally Version2.7.2 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Looking at the latest relevant jquery 3.4 code (which sets all https://github.com/jquery/jquery/blob/master/src/ajax.js#L655-L665 I don't see any reason why providing your Basic-Auth headers (either as Anyway, as the FUI docs say
and using the formElm.api({
action: "do login",
headers: {
"Authorization": "Basic " + btoa($('[name=email]').val() + ":" + $('[name=password]').val())
},
onComplete: function(response, elm, xhr) {
alert(xhr.status);
}
}); |
Beta Was this translation helpful? Give feedback.
-
That doesn't work though. It seems like that header is completely ignored, as 401 errors are consistently returned. I verified with the one I posted above. Using jQuery 3.3.1, but newer versions don't mention any change in this aspect. I also checked the underlining code, but could't figure out the difference between EDIT: |
Beta Was this translation helpful? Give feedback.
-
@aardbol Ah, yes, sure. Using the Something like formElm.
.api({
url: 'https://httpstat.us/401'
})
; |
Beta Was this translation helpful? Give feedback.
-
I tested again with FUI 2.7.5 and this issue isn't happening with it. I think (at first sight) I traced it back to issue #497. I'll test with the latest version next time before I create a new issue :-) |
Beta Was this translation helpful? Give feedback.
I tested again with FUI 2.7.5 and this issue isn't happening with it. I think (at first sight) I traced it back to issue #497.
I'll test with the latest version next time before I create a new issue :-)