Skip to content

Question mark is replaced by 'jQuery1520046861610282212496_1411972375451'. #1799

Closed

Description

@mgol

Originally reported by wjj871125 at: http://bugs.jquery.com/ticket/15249

Code as follows:

var content = 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'.

jQuery code

data = data.replace( jsre, replace );

jQuery code end.

These codes maybe need to optimize.

Issue reported for jQuery 1.5.2

Activity

  1. mgol commented on Oct 21, 2014

    @mgol
    MemberAuthor

    Comment author: dmethvin

    We should either document this or fix it so that it only does so for the currently-documented case of jsonp.

  2. dmethvin commented on Oct 29, 2014

    @dmethvin
    Member

    @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?

  3. jaubourg commented on Oct 29, 2014

    @jaubourg
    Member

    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.

  4. iamnotserious commented on Nov 27, 2014

    @iamnotserious

    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.

  5. timmywil commented on Jan 15, 2016

    @timmywil
    Member

    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?

  6. timmywil commented on Jan 25, 2016

    @timmywil
    Member

    Opened docs issue: jquery/api.jquery.com#878.

  7. locked as resolved and limited conversation to collaborators on Jun 18, 2018
  8. mgol commented on Jul 22, 2020

    @mgol
    MemberAuthor

    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.

  9. reopened this on Jul 22, 2020
  10. added this to the 4.0.0 milestone on Jul 22, 2020
  11. self-assigned this
    on Jul 22, 2020
  12. added a commit that references this issue on Jul 22, 2020
    5f93f8e
  13. added a commit that references this issue on Jul 27, 2020
    e7b3bc4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions