in reply to Sending file as "TEXT" or "BLOB"
First, I would very strongly recommend you look into something like jQuery to make your life with JavaScript easier, and that you don't hand-craft your responses from Perl. Though I'd normally recommend something like Mojolicious, that may be too big of a jump here, and at the very least look into one of the CGI.pm alternatives, like maybe CGI::Lite. See also UP-TO-DATE Comparison of CGI Alternatives.
Anyway, on to the problem at hand: XMLHttpRequest.responseType is a setting for the request*, and is not a return value indicating the type of the response. In theory, you could look at xhttp.getResponseHeader('content-type') instead. However, you might want to consider not differentiating responses on Content-Type, but on HTTP status codes instead. And as bliako described, another option is to wrap your data in JSON, so you can send status responses to clients that way, then HTTP error codes can be reserved for lower-level errors.
* Update: To clarify, perhaps a better way to describe it is a configuration setting for the XHR for what kind of a response the XHR should expect, and my understanding from reading up on it and testing a bit is that its value is not changed by the XHR depending on what it receives as a response.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sending file as "TEXT" or "BLOB"
by bliako (Abbot) on Feb 25, 2021 at 07:59 UTC |