---
title: "JSON.stringify is sending empty string"  
description: "JSON.stringify is sending empty string"  
author: "Anonymous User"  
published: 2014-11-26  
updated: 2014-11-27  
canonical: https://www.mindstick.com/forum/12697/json-stringify-is-sending-empty-string  
category: "asp.net"  
tags: ["jquery", "json", "string"]  
reading_time: 3 minutes  

---

# JSON.stringify is sending empty string

I am using jQuery 1.7.2 and [jQuery Validation](https://www.mindstick.com/forum/158280/how-to-include-jquery-validation-in-a-web-page) 1.8.1 with asp.net. In jQuery Validation there is one [option](https://www.mindstick.com/forum/159391/jquery-get-selected-option-from-dropdown) called [remote](https://www.mindstick.com/articles/85431/remote-employee-training-tips-tricks) it need ajax call to [web service](https://www.mindstick.com/articles/895/web-service-introduction). My thing is I am checking id is [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) use or not. I am using JSON.stringify to post the value to the web service but it will send empty [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) but if I send without JSON.stringify, I can see the value.

My code is as below. So how can we solve this

```
$(document).ready(function () {    var validator = $("#form1").validate({      rules: {        ctl00$ContentPlaceHolder$txCivilID: {          required: true,          rangelength: [12,12],          digits: true,          remote: {            url: "CivilID.aspx/IsAlreadyAvailable",            type: "post",            contentType: "application/json; charset=utf-8",            dataType: "json",            data: JSON.stringify({ civilID: $('#<%=txCivilID.ClientID%>').val() }),            dataFilter: function (data) {              var msg = JSON.parse(data);              if (msg.hasOwnProperty('d'))                return msg.d;              else                return msg;            }          }        },        ctl00$ContentPlaceHolder$txFirstName: {          required: true        },        ctl00$ContentPlaceHolder$txLastName: {          required: true        },        ctl00$ContentPlaceHolder$txMobile: {          required: true,          rangelength: [8,8],          digits: true        },        ctl00$ContentPlaceHolder$dpUserType: {          required: true        }      },      messages: {        ctl00$ContentPlaceHolder$txCivilID: {          required: "Civil for is required!",          rangelength: "Civil for should be {0} in length!",          digits: "Civil for should be only numbers!",          remote: "Civil ID already exists !!!"        },        ctl00$ContentPlaceHolder$txFirstName: "First Name is required!",        ctl00$ContentPlaceHolder$txLastName: "Last Name is required!",        ctl00$ContentPlaceHolder$txMobile: {          required: "Mobile number is required!",          rangelength: "Mobile number should be {0} in length!",          digits: "Mobile number should be only numbers!"        },        ctl00$ContentPlaceHolder$dpUserType: "Select User Type !"      },      errorPlacement: function (error, element) {        $('label[for="' + element.attr("id") + '"]').text(error.text());      }    });  });  
```

**Render [Version](https://www.mindstick.com/articles/12845/things-to-remember-while-migrating-odoo-to-a-better-version) of [Javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)**

```
<script type="text/javascript">$(document).ready(function () {    var validator = $("#form1").validate({      rules: {        ctl00$ContentPlaceHolder$txCivilID: {          required: true,          rangelength: [12,12],          digits: true,          remote: {            url: "CivilID.aspx/IsAlreadyAvailable",            type: "post",            contentType: "application/json; charset=utf-8",            dataType: "json",            data: '{ civilID:' + JSON.stringify($('#ContentPlaceHolder_txCivilID').val()) + '}',            dataFilter: function (data) {              var msg = JSON.parse(data);              if (msg.hasOwnProperty('d'))                return msg.d;              else                return msg;            }          }        },        ctl00$ContentPlaceHolder$txFirstName: {          required: true        },        ctl00$ContentPlaceHolder$txLastName: {          required: true        },        ctl00$ContentPlaceHolder$txMobile: {          required: true,          rangelength: [8,8],          digits: true        },        ctl00$ContentPlaceHolder$dpUserType: {          required: true        }      },      messages: {        ctl00$ContentPlaceHolder$txCivilID: {          required: "Civil for is required!",          rangelength: "Civil for should be {0} in length!",          digits: "Civil for should be only numbers!",          remote: "Civil ID already exists !!!"        },        ctl00$ContentPlaceHolder$txFirstName: "First Name is required!",        ctl00$ContentPlaceHolder$txLastName: "Last Name is required!",        ctl00$ContentPlaceHolder$txMobile: {          required: "Mobile number is required!",          rangelength: "Mobile number should be {0} in length!",          digits: "Mobile number should be only numbers!"        },        ctl00$ContentPlaceHolder$dpUserType: "Select User Type !"      },      errorPlacement: function (error, element) {        $('label[for="' + element.attr("id") + '"]').text(error.text());      }    });  });
```

## Replies

### Reply by Anonymous User

Try changing this line:

```
 data:JSON.stringify({ civilID: $('#<%=txCivilID.ClientID%>').val() }),
```

to this...

```
 data:JSON.stringify('{ civilID:' + $('#<%=txCivilID.ClientID%>').val() + '}'),
```

As that didnt work have you thought about offloading the data bit to a function:

```
function getCivilIdData() {  var data = {};  data['civilId'] =$('#<%=txCivilID.ClientID%>').val();  return data;}
```

Then change your other line to this:

data: JSON.stringify(getCivilIdData()),


---

Original Source: https://www.mindstick.com/forum/12697/json-stringify-is-sending-empty-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
