#9658 closed bug (invalid)
$.ajax should not prepend & to query string data when joining it to a url ending with ?
Reported by: | abarrett | Owned by: | abarrett |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | ajax | Version: | git |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
An ampersand is unnecessarily prepended to the query string data of a GET request when the URL ends with a question mark.
$.get('foo?', { bar: 42 });
The above example will fetch the URL foo?&bar=42
instead of foo?bar=42
.
Concatenation of the URL and query string appears to be performed in [email protected], with an additional concatenation at L660 when attempting to defeat caching mechanisms.
Those two lines seem to be the only places the rquery regexp is used.
The example may look contrived, but I stumbled across this when using a simple ?
as the URL to fetch the current resource with a different query string.
Change History (4)
comment:1 Changed 12 years ago by
Component: | unfiled → ajax |
---|---|
Owner: | set to abarrett |
Priority: | undecided → low |
Status: | new → pending |
comment:2 Changed 12 years ago by
Status: | pending → new |
---|
Here is a QUnit test case against edge on jsFiddle: http://jsfiddle.net/alexb/mLS45/
comment:3 follow-up: 4 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
If you put the question mark in your url, then ajax has to append the parameters the way it does. It cannot guess whether this is intentional on your part or not and takes the safest route, in case this is part of a custom query string scheme that would accept empty string as some kind of id (think myurl?service¶m1=value1&...).
comment:4 Changed 12 years ago by
Replying to jaubourg:
If you put the question mark in your url, then ajax has to append the parameters the way it does. It cannot guess whether this is intentional on your part or not and takes the safest route, in case this is part of a custom query string scheme that would accept empty string as some kind of id (think myurl?service¶m1=value1&...).
That is a valid point.
How about supporting the special case of a single ?
as the URL? As far as I am aware, there is no other way to request the current resource with a different query string.
Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsfiddle.net that reproduces the issue experienced to help us assess your ticket.
Additionally, test against the jQuery (edge) version to ensure the issue still exists.