Bug Tracker

Opened 11 years ago

Closed 11 years ago

#10975 closed bug (invalid)

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:


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/

Change History (1)

comment:1 Changed 11 years ago by jaubourg

Resolution: invalid
Status: newclosed

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.dataTypes:


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

Version 0, edited 11 years ago by jaubourg (next)
Note: See TracTickets for help on using tickets.