Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery.ajax: Document special handling of a double question mark #1171

Merged
merged 2 commits into from
Aug 24, 2020

Conversation

mgol
Copy link
Member

@mgol mgol commented Jul 22, 2020

This is the text provided by @dmethvin in #1005 (comment) that I formatted & split into 3 paragraphs.

Fixes gh-999
Ref gh-1005

Co-authored-by: Dave Methvin [email protected]

@mgol mgol requested a review from a team July 22, 2020 12:25
@mgol mgol requested a review from dmethvin July 22, 2020 12:25
@mgol
Copy link
Member Author

mgol commented Jul 22, 2020

BTW, is it just the double question mark? Isn't the single one replaced as well?

@mgol
Copy link
Member Author

mgol commented Jul 22, 2020

From the code it seems that ?? is replaced unconditionally and ? only if followed by =. The regex is:

/(=)\?(?=&|$)|\?\?/

See the visualization at:
https://regexper.com/#%2F%28%3D%29%5C%3F%28%3F%3D%26%7C%24%29%7C%5C%3F%5C%3F%2F
Screen Shot 2020-07-22 at 15 56 47

<desc>
<p>Data to be sent to the server. If the HTTP method is one that cannot have an entity body, such as GET, the <code>data</code> is appended to the URL.</p>
<p>When <code>data</code> is an object, jQuery generates the data string from the object's key/value pairs unless the <code>processData</code> option is set to <code>false</code>. For example, <code>{ a: "bc", d: "e,f" }</code> is converted to the string <code>"a=bc&amp;d=e%2Cf"</code>. If the value is an array, jQuery serializes multiple values with same key based on the value of the <code>traditional</code> setting (described below). For example, <code>{ a: [1,2] }</code> becomes the string <code>"a%5B%5D=1&amp;a%5B%5D=2"</code> with the default <code>traditional: false</code> setting.</p>
<p>When <code>data</code> is passed as a string it should <strong>already be encoded</strong> using the correct encoding for <code>contentType</code>, which by default is <code>application/x-www-form-urlencoded</code>. If the string contains a double question mark (<code>??</code>) it is replaced with a value generated by jQuery that is unique for each copy of the library on the page (e.g. <code>jQuery21406515378922229067_1479880736745</code>).</p>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document it only happens for dataType: "jsonp" or dataType: "json" and the latter will no longer trigger it in jQuery 4.0+.

@mgol
Copy link
Member Author

mgol commented Jul 22, 2020

We also need to take jquery/jquery#4754 into account - in jQuery 4 the logic will only be triggered for requests with dataType: "jsonp".

@mgol
Copy link
Member Author

mgol commented Aug 24, 2020

I created the issue for jQuery 4.0: #1176.

@mgol mgol force-pushed the ajax-question-mark-replaced branch from 0c831b9 to 493d13b Compare August 24, 2020 15:28
@mgol
Copy link
Member Author

mgol commented Aug 24, 2020

@timmywil I rebased the PR & added a new fixup commit with the changes from my comments.

@mgol mgol merged commit df1f7b0 into jquery:master Aug 24, 2020
@mgol mgol deleted the ajax-question-mark-replaced branch August 24, 2020 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Issue in Ajax Call
2 participants