I have a complex form, in which the user has some information to make some selection and to fill with the information There is also some Textera this form works great and the data is passed through JSON for my MVC controller and all the works are fine.
Although being a user, users have found me that some "$ $$ & amp; etc .. and because of them JSON is being formatted incorrectly, therefore the controller action is not bound correctly .
So my question is how can I convert text input to user in sign language so that it creates a valid JSON. / P>
The way I gather the current data Here's what:
var TelNo = $ ("# TelNo"). Var EmailMessage = $ ("# EmailMessage"). Val ();
> Jason to avoid characters There is no real work for this.
One such task will be done
function makeSafe (jsonf) {jsonf = JSON.stringify (Jsonf); jsonf = jsonf .replace (/ \\ n / g, "\\ n") .replace (/ \\ '/ g,' \\ '") .replace (/ \\" / g, "\" "\." \ \ T ") .replace (/ \\ b / g," \\ b ") .replace (/ \\ f / g," \\ f "); Return jsonf; } then you can
email messaging = messaging (email message); I've added it to my string object so that whenever I need it I can reference it
String.prototype.makeSafe = function () {Change it (/ \\ n / g, "\\ n"). Replace (/ \\ '/ g,' \\ ''). Replace (/ \\ "/ g," \ "" \ "") .replace (/ \\ & amp; / g, "\\ and more") .. (/ \\ r / g, "\\ r") .replace (/ \\ t / g, "\\ t"). .replace (/ \\ b / g, "\\ b") .replace (/ \\ f / g, "\\ f"); }; Var EmailMessage = $ ("# EmailMessage"). Val () EmailMessage = EmailMessage.makeSafe ();
No comments:
Post a Comment