Skip to main content

Bug Tracker

Side navigation

#10209 closed bug (invalid)

Opened September 07, 2011 04:33AM UTC

Closed September 23, 2011 08:05AM UTC

Last modified September 25, 2011 05:09AM UTC

Intentional: $.get & $.post may have the arguments passed in a way that the callback will not be the last argument

Reported by: joe@gcnymarketing.com Owned by: joe@gcnymarketing.com
Priority: low Milestone: None
Component: ajax Version: 1.6.3
Keywords: Cc:
Blocked by: Blocking:
Description

John Resig has highlighted the importance of API consistency numerous times. As an example, he says that jQuery is set up to ALWAYS take the callback function as the last parameter.

However, $.get & $.post can both get a "dataType" parameter after the callback (all the way back to jQuery 1.0). Although this is not practically a bug (since this is intentional) it is against the API consistency theory.

Attachments (0)
Change History (8)

Changed September 07, 2011 04:47AM UTC by rwaldron comment:1

component: unfiledajax
owner: → joe@gcnymarketing.com
priority: undecidedlow
status: newpending

So, are you suggesting that jQuery should break compat all the way back to 1.0? Or should we try John for heresy?

Changed September 08, 2011 06:15PM UTC by anonymous comment:2

Replying to [comment:1 rwaldron]:

So, are you suggesting that jQuery should break compat all the way back to 1.0? Or should we try John for heresy?

Of course not. While some have called me mad, I've yet to be titled lunatic.

All I'm proposing is to ''add'' the option to pass the ''dataType'' before the success callback. Since ''dataType'' is always a string and the success callback is always, well, a function (and risking the Dunning–Kruger effect), this should be pretty easy to implement.

Changed September 08, 2011 08:57PM UTC by anonymous comment:3

Replying to [ticket:10209 joe@…]:

John Resig has highlighted the importance of API consistency numerous times. As an example, he says that jQuery is set up to ALWAYS take the callback function as the last parameter. However, $.get & $.post can both get a "dataType" parameter after the callback (all the way back to jQuery 1.0). Although this is not practically a bug (since this is intentional) it is against the API consistency theory.

Here's my proposed fix:

 // allow for callback to be passed in as last argument
if ( jQuery.isFunction(type) ) {
   var tempType = callback;
   callback = type;
   type = tempType;
}

Changed September 08, 2011 08:59PM UTC by rwaldron comment:4

_comment0: As long as you're content-type headers are correct in the server's response, jQuery will handle the dataType for you, which means you wouldn't need to define that param anyway...1315518151133335

As long as your content-type headers are correct in the server's response, jQuery will handle the dataType for you, which means you wouldn't need to define that param anyway...

Changed September 08, 2011 09:32PM UTC by anonymous comment:5

Replying to [comment:4 rwaldron]:

As long as you're content-type headers are correct in the server's response, jQuery will handle the dataType for you, which means you wouldn't need to define that param anyway...

I don't understand what you're trying to say. jQuery ''does'' support incorrect content-type headers (by setting the dataTpe), and the API should be consistent with the rest of jQuery.

Are you proposing to get rid of the dataType argument altogether?

Changed September 08, 2011 09:47PM UTC by rwaldron comment:6

certainly not... I just think this is a completely unnecessary change.

Changed September 23, 2011 08:05AM UTC by trac-o-bot comment:7

resolution: → invalid
status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Changed September 25, 2011 05:09AM UTC by joe@gcnymarketing.com comment:8

Replying to [comment:7 trac-o-bot]:

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

I truly believe that this should be addressed, since it's such an easy fix.

I've done all the work, and modified the above solution to take into account all possible scenarios ([url, data, dataType, success], [url, dataType, success] & [url, non-primitive dataType, success]).

I created a fiddle with the code, as well as a test for all variations possible (also showing that there's no regression):

http://jsfiddle.net/afC5g/1/