Skip to main content

Bug Tracker

Side navigation

#10975 closed bug (invalid)

Opened December 07, 2011 06:05PM UTC

Closed December 07, 2011 11:51PM UTC

AJAX: Dynamically modifying the options.dataType in an ajaxPrefilter doesn't trigger the correct ajax converter.

Reported by: ralphholzmann Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

I'm writing an app against a backend that I don't have access to. The backend is returning data in the wrong format, so I need to modify the data returned from the server for ''every'' request before it passes it along to the ajax success callback.

So I set up an ajax converter that will make the necessary modifications under the dataType "json fix", and it works great! \\o/.

However, rather than go through my entire app and change the dataType for each ajax request, I thought it would be easier to set up an ajax prefilter that checks if the dataType is json, and if it is, adds " fix" to the dataType, thus triggering the converter. Unfortunately, this doesn't work. It works fine if I have the dataType originally set to "json fix", but dynamically adding it via an ajax prefilter does not work. :(

Test case: http://jsfiddle.net/DtpsB/1/

Attachments (0)
Change History (1)

Changed December 07, 2011 11:51PM UTC by jaubourg comment:1

_comment0: That's because modifying ptions.dataType option won't do a thing: $.ajax() already split it as an array. You can simply toy with the actual internal array, options.dataType'''s''': \ \ http://jsfiddle.net/FdGzS/ \ \ Please note that you can specify the dataType for which your prefilter is to be executed (which is spot on in your use case).1323301929730498
_comment1: That's because modifying options.dataType option won't do a thing: $.ajax() already split it as an array. You can simply toy with the actual internal array, options.dataType'''s''': \ \ http://jsfiddle.net/FdGzS/ \ \ Please note that you can specify the dataType for which your prefilter is to be executed (which is spot on in your use case).1323302207934232
resolution: → invalid
status: newclosed

That's because modifying options.dataType won't do a thing: $.ajax() already split it as an array. You can simply toy with the actual internal array, options.dataTypes:

http://jsfiddle.net/FdGzS/

Please note that you can specify the dataType for which your prefilter is to be executed (which is spot on in your use case).