Home >Web Front-end >JS Tutorial >Solution to the unresponsive execution of jquery function $.post under javascript_javascript skills

Solution to the unresponsive execution of jquery function $.post under javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:55:491131browse

When writing a javascirpt program, use the $.post method to send data. If the characters in the data contain '<', $.post will not be executed successfully.

Copy code The code is as follows:

var jsonstr='{"value":"abcd< efg"}';
$.post(
url,
{ "jsonstr": jsonstr },
function (data, status) {
});

It needs to be escaped before use. After escaping using the transferredChars function below, pass the data $.post to execute.

This function replaces '<' and '>' with '<' and '>' respectively.

Copy code The code is as follows:

transferredChars=function (htmlChars) {
var tcs = htmlChars.replace(/tcs = tcs.replace(/>/g, ">");
return tcs;
}

Copy code The code is as follows:

var jsonstr='{"value" :"abcdjsonstr=transferredChars(jsonstr);
$.post(
url,
{ "jsonstr": jsonstr },
function (data, status ) {
});

The jquery version used is 1.7.1.min
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn