You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question mark is replaced by 'jQuery1520046861610282212496_1411972375451'. #1799
varcontent=document.getElementById("content").value;jQuery.ajax({type:'post',url:'add.php',data:"content="+content,// value is '?'dataType : "json",success:function(response){alert('success:'+response.msg);},error: function(msg){alert(msg);}});
Code ends.
When the parameter 'content' value is '?' or '??', its content is replaced by similar content as 'jQuery1520046861610282212496_1411972375451'.
This is due to the fact $.getJSON is able to perform jsonp requests (has been since before the 1.5 version btw). But there's no argument to trigger this behaviour. As a consequence, the ajax infrastructure has to control the presence of the callback placeholder in the url in case of a json request in order to promote it as a jsonp request.
Fix would be to test the presence of the placeholder in $.getJSON itself and then set the dataType accordingly but it would break the fact you can promote a json request as jsonp by providing a url with placeholder in $.ajax proper.
Not that I think this would be used as much as in the $.getJSON scenario.
I encountered a similar issue as well. It exists in the latest version of jQuery too.
To those who want an immediate fix, using the "contentType" property to set the content-type seems to fix it.
After further review, I don't think we want to break the ability to promote json requests to jsonp. We may just want to document that you can set contentType to avoid this?
This will be fixed in jQuery 4 by the removal of the JSON-to-JSONP auto-promotion logic; the replacement will only be triggered if dataType is set to "jsonp". See issue #3376 & PR #4754.
Activity
mgol commentedon Oct 21, 2014
Comment author: dmethvin
We should either document this or fix it so that it only does so for the currently-documented case of jsonp.
dmethvin commentedon Oct 29, 2014
@jaubourg As I read the docs, we should only be replacing
?in the JSONP case. Is there a reason to do it in other cases?jaubourg commentedon Oct 29, 2014
This is due to the fact
$.getJSONis able to performjsonprequests (has been since before the 1.5 version btw). But there's no argument to trigger this behaviour. As a consequence, the ajax infrastructure has to control the presence of the callback placeholder in the url in case of ajsonrequest in order to promote it as ajsonprequest.Fix would be to test the presence of the placeholder in
$.getJSONitself and then set thedataTypeaccordingly but it would break the fact you can promote ajsonrequest asjsonpby providing a url with placeholder in$.ajaxproper.Not that I think this would be used as much as in the
$.getJSONscenario.iamnotserious commentedon Nov 27, 2014
I encountered a similar issue as well. It exists in the latest version of jQuery too.
To those who want an immediate fix, using the "contentType" property to set the content-type seems to fix it.
timmywil commentedon Jan 15, 2016
After further review, I don't think we want to break the ability to promote
jsonrequests tojsonp. We may just want to document that you can set contentType to avoid this?timmywil commentedon Jan 25, 2016
Opened docs issue: jquery/api.jquery.com#878.
MDL-53291 javascript: fix jquery ajax requests when data contains ??
MDL-53291 javascript: fix jquery ajax requests when data contains ??
MDL-53291 javascript: fix jquery ajax requests when data contains ??
Prevent milestone report from turning ?? into weird timestamp.
mgol commentedon Jul 22, 2020
This will be fixed in jQuery 4 by the removal of the JSON-to-JSONP auto-promotion logic; the replacement will only be triggered if
dataTypeis set to"jsonp". See issue #3376 & PR #4754.Ajax: Drop the json to jsonp auto-promotion logic
Ajax: Drop the json to jsonp auto-promotion logic