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

首頁 > 開發 > AJAX > 正文

AJAX 異步傳輸數據的問題

2024-09-01 08:29:29
字體:
來源:轉載
供稿:網友
要異步傳輸的數據:
Xml代碼
....
<action xsi:type="basic:JavaScript" script="index += 1;"/>
....
Ajax異步傳輸代碼:
Js代碼
代碼如下:
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,最終導致在后臺Servlet中得到得到數據+被空格代替,使得script中的index += 1;變成了index = 1;從而導致后臺Java代碼在跑script出現死循環。
在網上搜索,發現content-type使用application/x-www-form-urlencoded后:
[來自http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1]寫道
代碼如下:
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來提交方式來發起request卻不會出現類似的問題,而form默認的Content-Type也是application/x-www-form-urlencoded:
Js代碼
代碼如下:
$('test').innerHTML = "<form target='_blank' id='test_form' action='./gen_feed' method='post'>"
+ "<input type='text' name='input' /><input type='text' name='script' />"
+ "<input type='text' name='feedGeneral' /><input type='hidden' name='format' 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();

仍未發現問題到底出在何處,暫做備忘。暫時把script中的‘+'都用‘-'代替,index += 1;改成index -= -1;呵呵,以后有人看到這段自動生成的詭異腳本,不知道會作何感想,但現在也只能如此。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高密市| 秦安县| 巫山县| 平江县| 洛川县| 北流市| 西乡县| 谷城县| 资中县| 新巴尔虎右旗| 高碑店市| 清镇市| 普兰店市| 资源县| 永仁县| 凉山| 搜索| 酉阳| 长宁区| 会东县| 灵石县| 长岭县| 大庆市| 南开区| 天等县| 郑州市| 康平县| 五华县| 白山市| 宜章县| 微山县| 肇州县| 永登县| 梧州市| 札达县| 大兴区| 丹寨县| 竹溪县| 石狮市| 交城县| 台南市|