国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > AJAX > 正文

AJAX 異步傳輸數(shù)據(jù)的問題

2024-09-01 08:31:40
字體:
供稿:網(wǎng)友
暫時(shí)把script中的‘+’都用‘-’代替,index += 1;改成index -= -1;呵呵,以后有人看到這段自動(dòng)生成的詭異腳本,不知道會(huì)作何感想,但現(xiàn)在也只能如此。

要異步傳輸?shù)臄?shù)據(jù):
Xml代碼
....
<action xsi:type="basic:JavaScript" script="index += 1;"/>
....
Ajax異步傳輸代碼:
Js代碼

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


var postData = "input="+ escape(inputJSON) +"&script="+escape(xml)+
"&feedGeneral=" + escape(feedGeneral);
XmlHttpRequest.open("POST",url,true);
XmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
XmlHttpRequest.send(postData);


postData在encode和unencode,最終導(dǎo)致在后臺(tái)Servlet中得到得到數(shù)據(jù)+被空格代替,使得script中的index += 1;變成了index = 1;從而導(dǎo)致后臺(tái)Java代碼在跑script出現(xiàn)死循環(huán)。
在網(wǎng)上搜索,發(fā)現(xiàn)content-type使用application/x-www-form-urlencoded后:
[來自#h-17.13.4.1]寫道

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


Control names and values are escaped. Space characters are replaced by `+', and then reserved characters are escaped as
described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal
digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').


然而使用form來提交方式來發(fā)起request卻不會(huì)出現(xiàn)類似的問題,而form默認(rèn)的Content-Type也是application/x-www-form-urlencoded:
Js代碼

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


$('test').innerHTML = "<form target='_blank' action='./gen_feed' method='post'>"
+ "<input type='text' /><input type='text' />"
+ "<input type='text' /><input type='hidden' value='" + this.feed_type + "'
/>"
+ "<input type='submit' value='gen' /></form>";
var test_form = $('test_form');
test_form.elements[0].value = inputJSON;
test_form.elements[1].value = script;
test_form.elements[2].value = feedGeneral;
test_form.submit();


仍未發(fā)現(xiàn)問題到底出在何處,暫做備忘。暫時(shí)把script中的‘+'都用‘-'代替,index += 1;改成index -= -1;呵呵,以后有人看到這段自動(dòng)生成的詭異腳本,不知道會(huì)作何感想,但現(xiàn)在也只能如此。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 竹北市| 花垣县| 喀什市| 平凉市| 朝阳市| 玉门市| 上杭县| 西宁市| 敦化市| 武汉市| 洛宁县| 东山县| 静安区| 彭山县| 方城县| 陆丰市| 香格里拉县| 监利县| 汤原县| 南投市| 高邮市| 屏山县| 连南| 铜鼓县| 榆社县| 色达县| 万全县| 庆云县| 平远县| 绩溪县| 鹤壁市| 桦甸市| 赞皇县| 叶城县| 洪湖市| 泾阳县| 木里| 玉山县| 威信县| 苗栗市| 旬阳县|