You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to retrieve an XML document via rx.Observable.ajax.get() and I've come across a few problems with the way the XHR.responseType field is handled.
The first is that the AJAX constructor sets a default .responseType of "json" if none is provided.
This is a problem because it means that non-JSON data cannot actually be retrieved via the default get() method. From the XHR response there are 3 ways to retrieve the body of the response: .response, .responseText, and .responseXML. If the .responseType is set then the body of the response must be successfully parsed by the associated parser or else the .response field is set to null. Note that .responseText is null unless the .responseType is unset or is set to "text". Similarly .responseXML is null unless the .responseType is unset or is set to "document".
The .responseType should be left unset as provides the most versatility, as then the .response, .responseText, and .responseXML fields may all be available depending on the source document.
The second is that a .responseType of "xml" is documented/used in the following code. The correct enumeration to request an XML response is "document".
I've been trying to retrieve an XML document via
rx.Observable.ajax.get()
and I've come across a few problems with the way theXHR.responseType
field is handled.The first is that the AJAX constructor sets a default
.responseType
of "json" if none is provided.rxjs/src/observable/dom/AjaxObservable.ts
Lines 155 to 166 in 7bb8280
Note that there is already a
getJSON()
method which sets this value explicitly.rxjs/src/observable/dom/AjaxObservable.ts
Lines 92 to 101 in 7bb8280
This is a problem because it means that non-JSON data cannot actually be retrieved via the default
get()
method. From the XHR response there are 3 ways to retrieve the body of the response:.response
,.responseText
, and.responseXML
. If the.responseType
is set then the body of the response must be successfully parsed by the associated parser or else the.response
field is set tonull
. Note that.responseText
is null unless the.responseType
is unset or is set to "text". Similarly.responseXML
is null unless the.responseType
is unset or is set to "document".The
.responseType
should be left unset as provides the most versatility, as then the.response
,.responseText
, and.responseXML
fields may all be available depending on the source document.The second is that a
.responseType
of "xml" is documented/used in the following code. The correct enumeration to request an XML response is "document".rxjs/src/observable/dom/AjaxObservable.ts
Lines 414 to 415 in 7bb8280
rxjs/src/observable/dom/AjaxObservable.ts
Lines 430 to 432 in 7bb8280
If it is preferred to use "xml" as a more user-friendly value this shouldn't be exposed to the XHR object.
rxjs/src/observable/dom/AjaxObservable.ts
Line 258 in 7bb8280
The text was updated successfully, but these errors were encountered: