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

2
  • if you send one question mark it goes through? Commented Sep 26, 2014 at 2:07
  • 1
    try it without the stringify. You don't really need it unless you want to send an object inside data Commented Sep 26, 2014 at 2:11

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

yeah, that did the trick for me! thanks a lot! i thought that would be handled if i specify the datatype:json...
that happens, dataType is for the client to use on the response from the server
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: "??"}
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.