Bug Tracker

Ticket #10975 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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/

Change History

comment:1 Changed 3 years ago by jaubourg

  • Status changed from new to closed
  • Resolution set to invalid

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).

Last edited 3 years ago by jaubourg (previous) (diff)
Note: See TracTickets for help on using tickets.