#4785 closed bug (duplicate)
$.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)
Change History (7)
Changed 14 years ago by
Attachment: | ajax-typefix.diff added |
---|
comment:1 Changed 14 years ago by
Cc: | DarkRyder added |
---|---|
Owner: | set to flesler |
comment:2 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
$.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.
comment:3 Changed 13 years ago by
I'm pretty sure he meant the dataType
parameter. So this ticket isn't invalid but actually a duplicate of #2452
comment:4 Changed 13 years ago by
Milestone: | 1.4 |
---|---|
Resolution: | invalid |
Status: | closed → reopened |
comment:5 Changed 13 years ago by
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
patch against r6388