During the compilation of the javascirpt program, the $. post method is used to send data. If the data contains '<', $. post cannot be successfully executed.
Copy codeThe Code is as follows:
Var jsonstr = '{"value": "abcd <efg "}';
$. Post (
Url,
{"Jsonstr": jsonstr },
Function (data, status ){
});
You need to escape it before using it. Use the following transferredChars function to escape it, and then pass the data $. post to execute it.
This function replaces '<' and '>' with '<' and '>' respectively '.
Copy codeThe Code is as follows:
TransferredChars = function (htmlChars ){
Var tcs = htmlChars. replace (/</g, "<");
Tcs = tcs. replace (/>/g, "> ");
Return tcs;
}
Copy codeThe Code is as follows:
Var jsonstr = '{"value": "abcd <efg "}';
Jsonstr = transferredChars (jsonstr );
$. Post (
Url,
{"Jsonstr": jsonstr },
Function (data, status ){
});
The jquery version used is 1.7.1.min.