From http://api.jquery.com/jQuery.ajax/ :
$. Ajax () converters support the mapping of data types to other data types. If, however, you want to map a custom data type to a known type (e.g. json), you must add a mapping between the Content-Type and the actual data type using the content option:
$.ajaxSetup({ contents: { mycustomtype: /mycustomtype/ }, converters: { "mycustomtype json": function ( result ) {
So what does this mean, your server response data type may be mycustomtype . And when the AJAX call receives the data, it will see that its data type is mycustomtype and matches the regular expression that we set (in the content): /mycustomtype/ and outputs the data to the converter we specified, for example. mycustomtype json() will try to convert the data to json.
More about converters :
converters["mycustomtype json"] means that the function specified here will be executed if you want to convert the format of mycustomtype to json , so the contents of this function will parse which will return json . You can specify other types of conversions, for example.
converters: { "mycustomtype json": converterFromCustomTypeToJson, // mycustomtype -> json "mycustomtype jsonp": converterFromCustomTypeToJsonP, // mycustomtype -> jsonp "mycustomtype text": converterFromCustomTypeToText, // mycustomtype -> text "text mycustomtype": converterFromTextToCustomType // text -> mycustomtype }
And you should write your own converter functions:
var converterFromCustomTypeToJson = function(result) { var jsonResult = ... return jsonResult; }, converterFromCustomTypeToJsonP = function(result) { var jsonPResult = ... return jsonPResult; }, converterFromCustomTypeToText = function(result) { var textResult = ... return textResult; }, converterFromTextToCustomType = function(result) { var customResult = ... return customResult; };
You would also like to avoid clutter with the default converters:
{ "* text": window.String, "text html": true, "text json": jQuery.parseJSON, "text xml": jQuery.parseXML }