JQuery adds some weird string to the provided data

Code for reproducing the error (put the following code on the html page and read the data presented in Fiddler. JQuery 1.4.2 works fine, the problem occurs in 1.5.1 and 1.5.2):

<html>
<head>
<script src="https://github.com/douglascrockford/JSON-js/raw/master/json2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
var data = { "Name": "test??", "testDesc": "testdesc??"};
  $.ajax({ 
    url: "submit.aspx/SubmitData", 
    data: JSON.stringify(data),
    type: "POST", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    cache: false
  }).success(function (msg) {});
</script>
</head>
<body></body>
</html>

I am using jQuery 1.5.1 to process data and send data to the server

function test(name, testDesc){
  var data = { "Name": name, "testDesc": testDesc};
  $.ajax({ 
    url: "submit.aspx/SubmitData", 
    data: JSON.stringify(data),
    type: "POST", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    cache: false
  }).success(function (msg) {//......});
}

Among the thousands of records, there are several records with a string like "jQuery151023383707909744822_1301931324827" and "jQuery151033911434971578497_1301989384660" in the data.

Is this a jQuery bug or any plugins that cause the problem?

: "?" . , StackOverflowjQuery151023383707909744822_1301931324827 . goodjQuery151023383707909744822_1301931324827 .

: . ""? "{" ":" testjQuery15103933552800185728_1302170988810 "," ":" fdsa "}"

+5
2

jQuery jQuery, # 8417, , , , ; , .

, : :

jQuery(function($) {

  $('#theButton').click(function go() {
    var data = { "Name": "test??", "testDesc": "description"};
    $.ajax({ 
      url: "/icece5", 
      data: JSON.stringify(data),
      type: "POST", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      cache: false
    });
  });
});

POST jsbin.com, , , , . Chrome dev, , JSON-P, .

, , jQuery, JSON ( ):

jQuery(function($) {

  $('#theButton').click(function go() {
    var data = { "Name": "test??", "testDesc": "description"};
    $.ajax({ 
      url: "/icece5", 
      data: JSON.stringify(data),
      type: "POST", 
      contentType: "application/json; charset=utf-8", 
      //dataType: "json", 
      cache: false
    });
  });
});

, , , . :

var data = { "Name": "test??", "testDesc": "testdesc??"};
$.ajax({ 
    url: "submit.aspx/SubmitData", 
    data: JSON.stringify(data),
    type: "POST", 
    contentType: "application/json; charset=utf-8", 
    dataType: "text",              // <== Tell jQuery you expect plain text
    cache: false
}).success(function (data) {
    data = jQuery.parseJSON(data); // <=== Then parse it yourself
});

jsFiddle.net jQuery, - . , ; , , ...


:

, , POST , JSON, (jQuery151023383707909744822_1301931324827 ..) jQuery "expando" ( , jQuery ) _ . jQuery JSON-P, :

1 326-1 329 jQuery-1.5.1.js:

// Unique for each copy of jQuery on the page
// Non-digits removed to match rinlinejQuery
expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),

( 7,029-7,035):

// Default jsonp settings
jQuery.ajaxSetup({
    jsonp: "callback",
    jsonpCallback: function() {
        return jQuery.expando + "_" + ( jsc++ );
    }
});

, , , , , , , .

JSON-P ? URL- , JSON-P . , .

ajaxSettings .. , , ( , ? ) 7,033 ( ), , , .

+4

, . @T.J. Crowder , . jQuery, .


jquery , , cache: false .

, , . .

+4

All Articles