当前位置: 首页 > 图文教程 > 网络编程 > AJAX技术 > AJAX 异步传输数据的问题

AJAX技术
ajax和asp.net的配置文件
关天asp.net ajax beta中在updatepnael中注册脚本的解决方案
ASP.NET AJAX Beta2 调用本地WebService的一些改变
Ajax+GridView+Xml的简易留言薄
PHP和AJAX打造高级RSS聚合器
注册起动脚本,ASP.NET AJAX的一项重要功能!
使用Ajax时的十个常犯的错误
如何在ASP.Net Ajax中调用WebService
xmlHTTP xmlDOC 与 C#中DataSet的结合 实现AJAX简单示例
争论:Ajax技术是否即将没落?
Ajax:拥抱JSON,让XML走开
AJAX有没有未来?
Ajax 框架ZK 2.2 发布
利用ProtoType框架完成的一个下拉框(asp:DropDownList)联动的AJAX例子
在ASP.NET AJAX中别使用mode=Legacy
ASP.NET AJAX RC Tip:页面中无UpdatePanel时UpdateProgress创建出错问题
ECMAScript基础类以及Asp.net Ajax对类Object的扩展
Asp.net Ajax 中的脚本错误: Sys未定义 的解决方法
基于AJAX的ASP.NET聊天室-如何建立共识
解开Ajax技术生命中的达芬奇密码

AJAX技术 中的 AJAX 异步传输数据的问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 56 ::
收藏到网摘: n/a

暂时把script中的‘+’都用‘-’代替,index += 1;改成index -= -1;呵呵,以后有人看到这段自动生成的诡异脚本,不知道会作何感想,但现在也只能如此。 要异步传输的数据:
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;呵呵,以后有人看到这段自动生成的诡异脚本,不知道会作何感想,但现在也只能如此。