欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javasciprt下jquery函數(shù)$.post執(zhí)行無響應(yīng)的解決方法

 更新時(shí)間:2014年03月13日 17:44:48   作者:  
這篇文章主要介紹了javasciprt下jquery函數(shù)$.post執(zhí)行無響應(yīng)的解決方法,需要的朋友可以參考下
在編寫javascirpt程序過程中,用$.post方法發(fā)送數(shù)據(jù),若數(shù)據(jù)中字符含有'<‘,將導(dǎo)致$.post無法成功執(zhí)行。
復(fù)制代碼 代碼如下:

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

需要將其轉(zhuǎn)義后再使用,使用下面的transferredChars函數(shù)轉(zhuǎn)義后,再傳遞數(shù)據(jù)$.post即能執(zhí)行。

此函數(shù)使用將'<'和‘>'分別替換為'&lt;'和‘&gt;'。
復(fù)制代碼 代碼如下:

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

復(fù)制代碼 代碼如下:

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

使用的jquery版本為1.7.1.min

相關(guān)文章

最新評(píng)論