jquery - JSON.stringify is sending empty string -


i using jquery 1.7.2 , jquery validation 1.8.1 asp.net. in jquery validation there 1 option called remote need ajax call web service. thing checking id use or not. using json.stringify post value web service send empty string if send without json.stringify, can see value.

my code below. how can 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 required!",           rangelength: "civil should {0} in length!",           digits: "civil should numbers!",           remote: "civil id exists !!!"         },         ctl00$contentplaceholder$txfirstname: "first name required!",         ctl00$contentplaceholder$txlastname: "last name required!",         ctl00$contentplaceholder$txmobile: {           required: "mobile number required!",           rangelength: "mobile number should {0} in length!",           digits: "mobile number should numbers!"         },         ctl00$contentplaceholder$dpusertype: "select user type !"       },       errorplacement: function (error, element) {         $('label[for="' + element.attr("id") + '"]').text(error.text());       }     });   });    

render version of 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 required!",           rangelength: "civil should {0} in length!",           digits: "civil should numbers!",           remote: "civil id exists !!!"         },         ctl00$contentplaceholder$txfirstname: "first name required!",         ctl00$contentplaceholder$txlastname: "last name required!",         ctl00$contentplaceholder$txmobile: {           required: "mobile number required!",           rangelength: "mobile number should {0} in length!",           digits: "mobile number should numbers!"         },         ctl00$contentplaceholder$dpusertype: "select user type !"       },       errorplacement: function (error, element) {         $('label[for="' + element.attr("id") + '"]').text(error.text());       }     });   });      

you dont need json.stringify() method there. because string. json.stringify() convert json object string. change code this

data: { civilid: $('#<%=txcivilid.clientid%>').val() }, 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -