﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gavin&#039;s Blog &#187; Ajax</title>
	<atom:link href="http://laigw.name/tag/ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://laigw.name</link>
	<description>Keep it simple, stupid. Simplicity is beauty.</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:14:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>自写一个较通用的Ajax处理类</title>
		<link>http://laigw.name/post/108.html</link>
		<comments>http://laigw.name/post/108.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 09:20:42 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[Web前端技术]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript面向对象]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=108</guid>
		<description><![CDATA[出于工作和学习的需要，参考《Ajax in Action》一书，自写了一个较通用的Ajax处理类：AjaxObject。通过创建一个AjaxObject实例，调用其方法：
sendRequest();
就可以实现对服务器的异步请求和响应，而且不受全局变量的限制。
其代码如下：


&#160;查看代码 JAVASCRIPT1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
&#160;
* define a javascript class, this is its constructor.
&#160;
* For using this class object, make sure define an outer Ajax Component(may be an object) &#34;ajaxComponent&#34;,
&#160;
* which must has two methods: handleMessage(req) and handleError(req),
&#160;
* for responsing handling successful message and error message.
&#160;
*/
&#160;
AjaxObject = function&#40;ajaxComponent, url, method&#41;&#123;
&#160;
this.ajaxComponent = ajaxComponent;
&#160;
this.url = url;
&#160;
this.method = method ? [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/108.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Struts框架下Ajax发送中文乱码问题的解决</title>
		<link>http://laigw.name/post/94.html</link>
		<comments>http://laigw.name/post/94.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 08:23:36 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[Web前端技术]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Struts]]></category>
		<category><![CDATA[中文乱码]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=94</guid>
		<description><![CDATA[在使用AJAX向服务器端发送中文数据时，出现乱码，折腾了很久，在网上也找了很多解决办法，比如全站UTF-8编码、请求头编码为中文、使用 javascript中的escape函数等等，但一一试过均无效。在绝望之际，找到了一篇和我的情况比较相近的文章(详见：http: //blog.csdn.net/wallimn/archive/2006/11/12/1380106.aspx)，在详细参考这篇文章的做法之后终于把问题解决。
现在，把自己的解决方法写出来，以便有需要的朋友不要再像我那样走弯路。
环境：WinXP + Eclipse，JSP + Struts，页面用JavaScript结合Ajax控制，页面和服务器都使用UTF-8编码。

MyActionForm的属性：

&#160;查看代码 JAVA1
2
3
4
5
private String nameEn = null;
&#160;
private String nameSc = null;
&#160;
private String nameTc = null;

Action(MyAction) 的excute方法里面代码：

&#160;查看代码 JAVA1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
MyActionForm maForm = &#40;MyActionForm&#41;form;
&#160;
// must decoding, or else it will disorderly code
&#160;
// 第二个设编码参数一定要设
&#160;
String strNameEn = java.net.URLDecoder.decode&#40;maForm.getNameEn&#40;&#41;, &#34;UTF-8&#34;&#41;;
&#160;
String strNameSc = java.net.URLDecoder.decode&#40;maForm.getNameSc&#40;&#41;, &#34;UTF-8&#34;&#41;;
&#160;
String strNameTc = java.net.URLDecoder.decode&#40;maForm.getNameTc&#40;&#41;, &#34;UTF-8&#34;&#41;;
&#160;
System.out.println&#40;&#34;strNameEn: &#34; + strNameEn&#41;;
&#160;
System.out.println&#40;&#34;strNameSc: &#34; + strNameSc&#41;;
&#160;
System.out.println&#40;&#34;strNameTc: &#34; + strNameTc&#41;;

客户端代码：

&#160;查看代码 [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/94.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

