Skip to main content

Bug Tracker

Side navigation

#4785 closed bug (duplicate)

Opened June 19, 2009 12:20AM UTC

Closed November 02, 2010 05:51PM UTC

Last modified November 02, 2010 05:51PM UTC

$.get() and $.post() ignore `type` when not passing `data`

Reported by: DarkRyder Owned by: flesler
Priority: minor Milestone:
Component: ajax Version: 1.3.2
Keywords: Cc: DarkRyder
Blocked by: Blocking:
Description

The $.get() and $.post() functions ignore the type parameter if only the data parameter is omitted. In other words, the following calls all identical in effect:

$.get("foo.php", onSuccess);
$.get("foo.php", onSuccess, "script");
$.get("foo.php", onSuccess, "html");
$.get("foo.php", onSuccess, "not a valid type");

The expected behavior for this particular combination of optional arguments is not explicitly stated in the documentation, but that fact that the first call works (that data is indeed optional) would seem to imply that the others should work as well.

The problem is the conditional block in each function which "shifts" the arguments when data is omitted:

get: function( url, data, callback, type ) {
    // shift arguments if data argument was ommited
    if ( jQuery.isFunction( data ) ) {
        callback = data;
        data = null;
    }

In the calls above where a type is supplied, it is assigned to the callback parameter, which then gets "overwritten" in this conditional block. This can be easily solved by adding an extra line to the beginning of the block:

get: function( url, data, callback, type ) {
    // shift arguments if data argument was omitted
    if ( jQuery.isFunction( data ) ) {
        type = callback;
        callback = data;
        data = null;
    }

Attached is a patch against the current HEAD (r6388).

Attachments (1)
  • ajax-typefix.diff (0.7 KB) - added by DarkRyder June 19, 2009 12:20AM UTC.

    patch against r6388

Change History (6)

Changed September 14, 2009 06:48PM UTC by flesler comment:1

cc: → DarkRyder
owner: → flesler

Changed November 01, 2010 10:23PM UTC by rwaldron comment:2

resolution: → invalid
status: newclosed

$.get and $.post do not have a type argument per your definition. They do have a dataType argument that defines the format of the data being returned in the server's response.

Changed November 02, 2010 10:37AM UTC by jitter comment:3

_comment0: I'm pretty sure he meant the `dataType` parameter. So this ticket isn't invalid but actually a duplicate of [http://bugs.jquery.com/ticket/2452 #2452] which has already been fixed1288694443116349

I'm pretty sure he meant the dataType parameter. So this ticket isn't invalid but actually a duplicate of ~~[http://bugs.jquery.com/ticket/2452 #2452]~~

Changed November 02, 2010 05:51PM UTC by rwaldron comment:4

milestone: 1.4
resolution: invalid
status: closedreopened

Changed November 02, 2010 05:51PM UTC by rwaldron comment:5

resolution: → duplicate
status: reopenedclosed

Changed November 02, 2010 05:51PM UTC by rwaldron comment:6

Duplicate of #2452.