dojo/_base/xhr.contentHandlers (version 1.10)

Summary

A map of available XHR transport handle types. Name matches the handleAs attribute passed to XHR calls.

A map of available XHR transport handle types. Name matches the handleAs attribute passed to XHR calls. Each contentHandler is called, passing the xhr object for manipulation. The return value from the contentHandler will be passed to the load or handle functions defined in the original xhr call.

Examples

Example 1

Creating a custom content-handler:

xhr.contentHandlers.makeCaps = function(xhr){
    return xhr.responseText.toUpperCase();
}
// and later:
dojo.xhrGet({
    url:"foo.txt",
    handleAs:"makeCaps",
    load: function(data){ /* data is a toUpper version of foo.txt */ }
});

Method Summary

  • auto(xhr)
  • javascript(xhr) A contentHandler which evaluates the response data, expecting it to be valid JavaScript
  • json(xhr) A contentHandler which returns a JavaScript object created from the response data
  • json-comment-filtered(xhr) A contentHandler which expects comment-filtered JSON.
  • json-comment-optional(xhr) A contentHandler which checks the presence of comment-filtered JSON and alternates between the json and json-comment-filtered contentHandlers.
  • text(xhr) A contentHandler which simply returns the plaintext response data
  • xml(xhr) A contentHandler returning an XML Document parsed from the response data

Methods

auto(xhr)
Defined by dojox/rpc/Service
Parameter Type Description
xhr undefined
javascript(xhr)
Defined by dojo/_base/xhr

A contentHandler which evaluates the response data, expecting it to be valid JavaScript

Parameter Type Description
xhr undefined
Returns:undefined
json(xhr)
Defined by dojo/_base/xhr

A contentHandler which returns a JavaScript object created from the response data

Parameter Type Description
xhr undefined
Returns:undefined
json-comment-filtered(xhr)
Defined by dojo/_base/xhr

A contentHandler which expects comment-filtered JSON.

A contentHandler which expects comment-filtered JSON. the json-comment-filtered option was implemented to prevent "JavaScript Hijacking", but it is less secure than standard JSON. Use standard JSON instead. JSON prefixing can be used to subvert hijacking.

Will throw a notice suggesting to use application/json mimetype, as json-commenting can introduce security issues. To decrease the chances of hijacking, use the standard json contentHandler, and prefix your "JSON" with: {}&&

use djConfig.useCommentedJson = true to turn off the notice

Parameter Type Description
xhr undefined
Returns:undefined
json-comment-optional(xhr)
Defined by dojo/_base/xhr

A contentHandler which checks the presence of comment-filtered JSON and alternates between the json and json-comment-filtered contentHandlers.

Parameter Type Description
xhr undefined
Returns:undefined
text(xhr)
Defined by dojo/_base/xhr

A contentHandler which simply returns the plaintext response data

Parameter Type Description
xhr undefined
Returns:undefined
xml(xhr)
Defined by dojo/_base/xhr

A contentHandler returning an XML Document parsed from the response data

Parameter Type Description
xhr undefined
Returns:undefined
Error in the documentation? Can’t find what you are looking for? Let us know!