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
<p><code>$.ajax()</code> converters support mapping data types to other data types. If, however, you want to map a custom data type to a known type (e.g <code>json</code>), you must added a correspondance between the response Content-Type and the actual data type using the <code>contents</code> option:</p>
290
+
291
+
<pre>
292
+
$.ajaxSetup({
293
+
contents: {
294
+
mycustomtype: /mycustomtype/
295
+
},
296
+
converters: {
297
+
"mycustomtype json": function ( result ) {
298
+
// do stuff
299
+
return newresult;
300
+
}
301
+
}
302
+
});
303
+
</pre>
304
+
305
+
<p>This extra map is necessary because the response Content-Types and data types never have a strict one-to-one correspondance (hence the regular expression).</p>
306
+
307
+
<p>To convert from a supported type (e.g <code>text</code>, <code>json</code>) to a custom data type and back again, use another pass-through converter:</p>
308
+
309
+
<pre>
310
+
$.ajaxSetup({
311
+
contents: {
312
+
mycustomtype: /mycustomtype/
313
+
},
314
+
converters: {
315
+
"text mycustomtype": true,
316
+
"mycustomtype json": function ( result ) {
317
+
// do stuff
318
+
return newresult;
319
+
}
320
+
}
321
+
});
322
+
</pre>
323
+
324
+
<p>The above now allows passing from <code>text</code> to <code>mycustomtype</code> and then <code>mycustomtype</code> to <code>json</code>.</p>
325
+
285
326
<h4>Extending Ajax</h4>
286
327
<p><strong>As of jQuery 1.5</strong>, jQuery's Ajax implementation includes prefilters, converters, and transports that allow you to extend Ajax with a great deal of flexibility. For more information about these advanced features, see the <ahref="http://api.jquery.com/extending-ajax/">Extending Ajax</a> page.</p>
0 commit comments