论坛首页 Web前端技术论坛

prototype 发送XML数据的问题。

浏览 14402 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-11-15  
这个东西不是js的问题,早告诉你了,看服务器是怎么实现的,所有XHR都是编码的,都是encodeURI过的,要么你自己使用XHR发送不编码的文件,使用各种函数库就一定会编码,如果java什么的会根据text/xml的header进行默认解码那是另外话题,一句话,http post是要进行编码的,除非是2进制不编码
0 请登录后投票
   发表时间:2007-11-16  
哦。。好的,谢谢大家!!
0 请登录后投票
   发表时间:2007-12-28  
rihoonet 写道
    var tt = '<root><name>student</name><age>12</age></root>'
    var myAjax = new Ajax.Request(
                    'http://localhost:8080/server/QueryData',
                    {method: 'post', parameters: tt, onComplete: showResponse}
                    );

  服务器上为什么接收的不是tt那样的数据,而是“%3Croot%3E%3Cname%3Estudent%3C%2Fname%3E%3Cage%3E12%3C%2Fage%3E%3C%2Froot%3E”?

用prototype的Ajax方法,如果发送的是xml,应该用post方法,而且不要用parameters参数,而是用postBody代替。
看prototype的源码,如果用parameters,它做了以下处理:
params = Hash.toQueryString(params);
在这里它被encodeURIComponent了,所以到后台的'<'和'>'就是那种字符了。

    var tt = '<root><name>student</name><age>12</age></root>'
    var myAjax = new Ajax.Request(
                    'http://localhost:8080/server/QueryData',
                    {method: 'post', postBody: tt, onComplete: showResponse}
                    );

0 请登录后投票
   发表时间:2007-12-29  
哦。。知道了,谢谢,等下我再试试。
0 请登录后投票
   发表时间:2007-12-29  
letle 正解
0 请登录后投票
   发表时间:2007-12-31  
十分感谢letle,收获不小。
0 请登录后投票
   发表时间:2008-07-10  
这个问题我也碰见过,客户端向服务器端请求需要转码
encodeURIComponent($text);
服务器端用的是php,然后再转成GB2312
$text=iconv("UTF-8","GB2312",$text);
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics