锁定老帖子 主题:prototype 发送XML数据的问题。
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-11-13
能不能讲解一下JAVA的,谢谢。
|
|
返回顶楼 | |
发表时间:2007-11-13
afcn0 写道 这个不是encoding的问题,post get提交不管是'application/x-www-form-urlencoded'还是text/xml都会urlencode的,这个解码只能在服务器端做,比如php的$_POST默认是做了urldecode动作的,而$HTTP_RAW_POST_DATA就是原始数据,这个和Prototype没什么关系,主要看服务器端接受有没有什么默认解码一系列的
直接发送 xmldom 就不用encode了 利用xml字符串 创建 DOMDocument 然后 send这个DOMDocument就不用编码了 |
|
返回顶楼 | |
发表时间:2007-11-13
所有使用Ajax提交的数据都是UTF-8格式的,所以你必须在服务器端坐一次转化,如果是XML的内容,建议使用XMLPULL
|
|
返回顶楼 | |
发表时间:2007-11-13
public org.deducation.data.QuestionBase doRequ(java.io.InputStream data)
throws org.xmlpull.v1.XmlPullParserException, IOException { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System .getProperty(XmlPullParserFactory.PROPERTY_NAME), null); factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); XmlPullParser xpp = factory.newPullParser(); // xpp.setInput(data, "GB2312"); xpp.setInput(data, "utf-8"); |
|
返回顶楼 | |
发表时间:2007-11-13
谢谢各位回答,好像真的是prototype的问题,我用下面的代码,是可以的:
<script type="text/javascript"> var xmlHttp; function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("microsoft.XMLHttp"); } else if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function createXML() { return "<root><name>student</name><age>12</age></root>"; } function AAAA1() { createXMLHttpRequest(); var xml = createXML(); var url = "http://localhost:8080/queryData"; xmlHttp.open("POST", url,true); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.setRequestHeader("Content-Type","aplication/x-www-form-urlencoded;"); xmlHttp.send(xml); } function handleStateChange() { if (xmlHttp.readyState==4) { if (xmlHttp.status==200) { alert("OK"); } } } </script> 但是用 <script> function AAAA() { var tt = "<root><name>student</name><age>12</age></root>"; var myAjax = new Ajax.Request( 'http://localhost:8080/queryData', {method: "post", encoding: "utf-8" ,contentType: "aplication/x-www-form-urlencoded", parameters: tt, onComplete: showResponse} ); function showResponse(originalRequest) { } } </script>却不成功,不知道大家还有什么好的方面没有。 |
|
返回顶楼 | |
发表时间:2007-11-13
对,就是Prototype默认编码了,1.60里面你可以看1191行
this.options.parameters = this.options.parameters.toQueryParams(); 和1217行 params = Object.toQueryString(params) 你要不编码,就直接Ajax.getTransport() |
|
返回顶楼 | |
发表时间:2007-11-13
谢谢afcn0 我用了编码,监视提交数据,发现编码是起来作用的,我现在不在办公室,明天将发送的内容帖上来。
|
|
返回顶楼 | |
发表时间:2007-11-14
POST /AppServer/BizData HTTP/1.1
Accept: text/javascript, text/html, application/xml, text/xml, */* Accept-Language: zh-cn x-prototype-version: 1.6.0 Referer: http://localhost:8080/queryData/Tester.html x-requested-with: XMLHttpRequest Content-Type: aplication/x-www-form-urlencoded; charset=utf-8 UA-CPU: x86 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; TencentTraveler ; Embedded Web Browser from: http://bsalsa.com/; .NET CLR 1.1.4322; .NET CLR 2.0.50727) Host: localhost:8080 Content-Length: 76 Connection: Keep-Alive Cache-Control: no-cache 有了Content-Type: aplication/x-www-form-urlencoded; charset=utf-8就说明起作用了啊。 |
|
返回顶楼 | |
发表时间:2007-11-14
ls, 你这贴啥意思 没明白
什么起作用了???? |
|
返回顶楼 | |
发表时间:2007-11-14
afcn0 写道 对,就是Prototype默认编码了,1.60里面你可以看1191行
this.options.parameters = this.options.parameters.toQueryParams(); 和1217行 params = Object.toQueryString(params) 你要不编码,就直接Ajax.getTransport() fins ,你好,我是针对上面的来说明编码设置起作用了。 |
|
返回顶楼 | |