Question: I'm using jquery ajax function.
I noticed an issue when I post JSON data to the server.

The type of post data is JSON. So I added the code to specify what I sent was JSON.

```
contentType: "application/json".

```

I wrote below code:

```
var data = {"data": "mytestdata" };
var option = {
     url: 'Handler1.ashx',
     type: 'POST',
     dataType: 'html',
     success: function (result) {
         alert(result);
     },
     data: data,
     contentType: "application/json"
 };
 $.ajax(option);

```

At the server side, I used below code:

```
string s = context.Request["data"];

```

But the result `s` was `null`.

Logically,setting `contentType="application/json"` and posting json data are perfect. But it's false.

Also I tried code in php file: 

```
echo $_POST["data"];

```

PHP says `$_POST["data"] doesn't exist`.

So I tried to remove the code -- `contentType: "application/json"`.

Now,everything is OK.

But it confused me.
 Why needn't set contentType as json when we post the real json data?

Answer: 
You don't need to do `contentType: "application/json"`, when you don't specify content type, it converts the data to be sent in http params, from the json..which are accessible via $\_GET, or $\_POST params..

But if you want to send json data only..you can try this code on server side to get the data:

```
<?php
$data = @file_get_contents('php://input');
print_r(json_decode($data));
?>

```
You were not sending JSON data back. jQuery considers it an error when the ajax content type is set to accept JSON, but malformed JSON is sent back.

`echo $_POST['data']` will likely throw the exception "Catchable fatal error: Object of class stdClass could not be converted to string" -- so that actually gets printed out. That's not valid JSON.

What you probably want to do is `echo json_encode($_POST['data']);`