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
Release: 2016-05-16 16:55:49
Original
1124 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template