AJAX 異步傳輸數(shù)據(jù)的問題
更新時間:2008年12月28日 21:50:17 作者:
暫時把script中的‘+’都用‘-’代替,index += 1;改成index -= -1;呵呵,以后有人看到這段自動生成的詭異腳本,不知道會作何感想,但現(xiàn)在也只能如此。
要異步傳輸?shù)臄?shù)據(jù):
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,最終導(dǎo)致在后臺Servlet中得到得到數(shù)據(jù)+被空格代替,使得script中的index += 1;變成了index = 1;從而導(dǎo)致后臺Java代碼在跑script出現(xiàn)死循環(huán)。
在網(wǎng)上搜索,發(fā)現(xiàn)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來提交方式來發(fā)起request卻不會出現(xiàn)類似的問題,而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();
仍未發(fā)現(xiàn)問題到底出在何處,暫做備忘。暫時把script中的‘+'都用‘-'代替,index += 1;改成index -= -1;呵呵,以后有人看到這段自動生成的詭異腳本,不知道會作何感想,但現(xiàn)在也只能如此。
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)致在后臺Servlet中得到得到數(shù)據(jù)+被空格代替,使得script中的index += 1;變成了index = 1;從而導(dǎo)致后臺Java代碼在跑script出現(xiàn)死循環(huán)。
在網(wǎng)上搜索,發(fā)現(xiàn)content-type使用application/x-www-form-urlencoded后:
[來自http://www.w3.org/TR/html401/interact/forms.html#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卻不會出現(xiàn)類似的問題,而form默認的Content-Type也是application/x-www-form-urlencoded:
Js代碼
復(fù)制代碼 代碼如下:
$('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();
仍未發(fā)現(xiàn)問題到底出在何處,暫做備忘。暫時把script中的‘+'都用‘-'代替,index += 1;改成index -= -1;呵呵,以后有人看到這段自動生成的詭異腳本,不知道會作何感想,但現(xiàn)在也只能如此。
相關(guān)文章
AJAX開發(fā)技術(shù)在PHP開發(fā)中的簡單應(yīng)用技巧
AJAX無疑是2005年炒的最熱的Web開發(fā)技術(shù)之一,當然,這個功勞離不開Google。我只是一個普通開發(fā)者,使用AJAX的地方不是特別多,我就簡單的把我使用的心得說一下。(本文假設(shè)用戶已經(jīng)具有JavaScript、HTML、CSS等基本的Web開發(fā)能力)2010-04-04
添加后臺list給前臺select標簽賦值簡單實現(xiàn)
本文為大家介紹下通過添加后臺list怎么實現(xiàn)給前臺select標簽賦值,具體代碼如下,感興趣的朋友可以參考下哈2013-07-07
JQuery的ajax的用法在asp中使用$.ajax()實現(xiàn)
ajax的出現(xiàn)解決了很多的疑難問題,同時帶來了很多的方便,本文講述一下JQuery的ajax的用法在asp中使用$.ajax()來表示,感興趣的朋友可以了解下,或許本文對你有所幫助2013-01-01
SpringMVC環(huán)境下實現(xiàn)的Ajax異步請求JSON格式數(shù)據(jù)
這篇文章主要介紹了SpringMVC環(huán)境下實現(xiàn)的Ajax異步請求JSON格式數(shù)據(jù)的相關(guān)資料,需要的朋友可以參考下2016-05-05
使用ajax技術(shù)實現(xiàn)txt彈出在頁面上的方法
下面小編就為大家?guī)硪黄褂胊jax技術(shù)實現(xiàn)txt彈出在頁面上的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08

