0

Something strange happens: when i want to post a string "??" via ajax to the server

$.ajax({
  type: 'POST',
  url: path,
  dataType: 'json',
  data: JSON.stringify({
    text: "??"
  })
});

it allways produces something like that in request to the server:

{"text":"jQuery21109622253710404038_1411696744993"}:

What is happening here? What the problem with double ? ?

Fabian
  • 1,806
  • 5
  • 25
  • 40

2 Answers2

1

You need to specify the content type;

$.ajax({
  type: 'POST',
  url: path,
  dataType: 'json',
  contentType: 'application/json; charset=utf-8', //<--This line
  data: JSON.stringify({
    text: "??"
  })
});

Check this similar question

Let me know if it works

Community
  • 1
  • 1
Felipe Pereira
  • 11,410
  • 4
  • 41
  • 45
0

Do not use JSON.stringify for data. It should work fine after removing that. See the code below.

$.ajax({
   type: 'POST',
   url: 'http://localhost/rnd/ajax.php',
   dataType: 'json',
   data: {text: "??"}
});
ButterflyRay
  • 395
  • 2
  • 11