AJAX 异步传输数据的问题
2008-12-28 12:38
295 查看
要异步传输的数据:Xml代码
![](http://fuliang.javaeye.com/images/icon_copy.gif)
....
<action xsi:type="basic:JavaScript" script="index += 1;"/>
....
Ajax异步传输代码:Js代码
![](http://fuliang.javaeye.com/images/icon_copy.gif)
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代码
![](http://fuliang.javaeye.com/images/icon_copy.gif)
$('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;呵呵,以后有人看到这段自动生成的诡异脚本,不知道会作何感想,但现在也只能如此。
![](http://fuliang.javaeye.com/images/icon_copy.gif)
....
<action xsi:type="basic:JavaScript" script="index += 1;"/>
....
Ajax异步传输代码:Js代码
![](http://fuliang.javaeye.com/images/icon_copy.gif)
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代码
![](http://fuliang.javaeye.com/images/icon_copy.gif)
$('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;呵呵,以后有人看到这段自动生成的诡异脚本,不知道会作何感想,但现在也只能如此。
相关文章推荐
- jquery异步ajax超大长度base64图片长字段数据传输问题解决办法和php后台处理办法
- AJAX 异步传输数据的问题
- AJAX 异步传输数据的问题
- 解决在循环中使用ajax异步时,数据的同步问题
- ajax异步数据使用显示红色200问题
- For循环中由于ajax异步导致的问题解决(增加alert数据正常,去掉alert之后数据错误)
- 处理从ajax得到的数据进行判断,ajax异步的问题
- Ajax传输数据时候乱码的问题
- ajax传输json数据遇到不执行success方法也不报错的问题
- ajax异步传输问题
- JSP和Servlet互相传输数据的过程中产生的乱码问题及解决方案(没有使用AJAX的情况)
- ajax异步问题导致的刷新页面数据不更新
- 【jQuery】解决在循环中使用ajax异步时,数据的同步问题
- Ajax的同步和异步数据传输
- 关于Microsoft.XMLHTTP或Ajax中异步获取数据的问题
- jQuery UI Autocomplete 使用 ajax 方法传输Json数据出现乱码问题的解决
- 分布式架构项目中各模块中页面发送ajax请求后台json数据的传输问题
- PHP和Ajax异步批量处理数据提交问题
- Ajax数据传输的一个问题
- ajax中文数据传输乱码问题以及zend framework escape()调用