javascript - How to perform a clean json for a carriage return? -
i've problem on clean json string on textarea.
i've form textarea. validation, sends email taking forms of information.
but error when pass line in textarea.
ma fonction js :
function submit() { var path = $(location).attr('href'); try { var parameters = '{ "url" : "' + escape(path) + '", "prénom" : "' + cleanjsonstring($("#inputfirstname").val()) + '", "nom" : "' + cleanjsonstring($("#inputlastname").val()) + '", "email" : "' + cleanjsonstring($("#inputemail").val()) + '", "message" : "' + cleanjsonstring($("#inputmessage").val()) + '", "captchachallenge" : "' + capchallenge + '", "captcharesponse" : "' + capresponse + '" }'; contentsubmit = $("#submitarea").html(); $("#submitarea").empty().html('<img src="/images/ajax-loader.gif" />'); jquery.ajax({ type: "post", url: '_vti_bin/json/service.svc/submit', contenttype: "application/json; charset=utf-8", datatype: 'json', data: parameters, success: function (msg) { submitsucceeded(msg); $("#submitarea").empty().html(contentsubmit); resetrealpersoncaptcha(); }, error: submitfailed }); } catch (e) { alert('error invoking service' + e); clearuploadpart(); } //recaptcha.reload(); }
the function clean values in json properties send valid json request :
function cleanjsonstring(str) { if (typeof str == 'undefined' || str == null) return ""; //clean values in json properties send valid json request return str.replace(/[/\\""]/g, "") .replace(/\\n/g, "") .replace(/\\&/g, "\\&") .replace(/\\r/g, "\\r") .replace(/\\t/g, "\\t") .replace(/\\b/g, "\\b") .replace(/\\f/g, "\\f"); }
and asp form :
<div id="content_title"> <h1>submit</h1> </div> <div class="submit"> <div class="left"> <div class="field"><input id="inputfirstname" type="text" value="first name *" class="watermark" name="firstname"/></div> <div class="field"><input id="inputlastname" type="text" value="last name *" class="watermark" name="lastname"/></div> <div class="field"><input id="inputemail" type="text" value="e-mail *" class="watermark" name="email"/></div> <div class="right"> **<div class="textarea"><textarea id="inputmessage" name="message" class="watermark">add message here</textarea></div>** <img id="other_upload_process3" alt="" style="height:20px; display:none;" src="/images/ajax-loader.gif"/> <img id="other_upload_success3" alt="" style="width:20px; height:20px; display:none;" src="/images/check.png"/> </div> <div style="float:left;width:100%; margin-top:30px;"> <div id="captchadiv"><input id="captchainput" type="text" value="enter validation text *" name="captchainput" class="watermark" style="margin-top:10px;"/></div> </div> <div class="clear"></div> <div class="submit_container" id="submitarea"> <a onclick="javascript:submit();" class="btn orange height_19 submit"><span> send form</span></a> </div> </div>
i don't understand why i've error when pass line in textarea. have idea ? error in json properties send valid json request ?
Comments
Post a Comment