ajax经典应用收藏
这网站想法很好...ziq.com
1<script language="javascript">
2// xmlhttp
3var XmlHttp = false;
4var XmlLocked = false;
5
6// init xmlhttp
7function InitXmlHttp()
8{
9 if (!XmlHttp)
10 {
11 try { XmlHttp = new ActiveXObject('Msxml1.XMLHTTP'); }
12 catch (e)
13 {
14 try { XmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); }
15 catch (e) { XmlHttp = false; }
16 }
17 if (!XmlHttp && (typeof XMLHttpRequest != 'undefined'))
18 XmlHttp = new XMLHttpRequest();
19 if (!XmlHttp)
20 {
21 alert('抱歉您的浏览器不支持 XmlHttp 对像, 彩字制造失败.');
22 return false;
23 }
24 }
25
26 // lock check
27 if (XmlLocked == true)
28 {
29 alert('XmlHttp 某一次操作还没有完成, 请稍候啦.');
30 return false;
31 }
32 return true;
33}
34
35// 取得图片
36function GetImage(form)
37{
38 var text = form.w.value;
39 var style = form.s.value;
40 var maxword = parseInt(form.m.value);
41 if (text == '')
42 {
43 alert('总该说点什么吧?');
44 form.w.focus();
45 }
46 else if (text.length > maxword)
47 {
48 alert('抱歉,此风格最多' + maxword + '字');
49 form.w.value = form.w.value.substring(0,maxword);
50 form.w.focus();
51 }
52 else
53 {
54 SetProcMsg('请稍候', false);
55 SendImageRequest(text, style);
56 document.getElementById('DemoDiv').style.display = '';
57 document.getElementById('DemoImg').src = 'img/title_wait.gif';
58 document.getElementById('DemoImg').title = text;
59 form.w.focus();
60 }
61}
62// 修改值时要隐藏
63function HideDemo()
64{
65 document.getElementById('DemoDiv').style.display = 'none';
66}
67
68// 复制地址值
69function CopyValue(input)
70{
71 input.select();
72 window.clipboardData.setData('text', input.value);
73 alert('已经拷入剪贴板!');
74}
75
76// 设定执行说明
77function SetProcMsg(msg, nr)
78{
79 if (msg != '' && nr) { setTimeout('SetProcMsg("",false)', 3000); }
80 document.getElementById('ProcMsg').innerHTML = msg;
81}
82
83// 图片地址回调
84function SetImageUrl(str)
85{
86 //SendImageRequest
87 var rtype = str.substring(0,2);
88 var rdata = str.substring(4);
89 if (rtype != 'OK')
90 {
91 alert(rdata);
92 HideDemo();
93 SetProcMsg('太遗憾了', true);
94 }
95 else
96 {
97 var form = document.zform;
98 var url = rdata.substring(2);
99 url = url.replace(/\+/, '%20');
100 form.t.value = 'http://img2.ziq.com/' + url;
101 form.b.value = '[img]' + form.t.value + '[/img]';
102 document.getElementById('DemoImg').src = url;
103
104 // mmslink
105 var mlink = 'http://tlt.7town.com/ZComImgDIY/step2.asp?imageUrl=';
106 mlink += encodeURIComponent(form.t.value) + '&uid=20398&a=&b=&c=&d=&e=&f=';
107 document.getElementById("MmsLink").href = mlink;
108 SetProcMsg('祝贺您!!!', true);
109 }
110}
111
112// 提交图片申请
113function SendImageRequest(w, s)
114{
115 if (!InitXmlHttp()) return false;
116
117 // send the request
118 var url = 'm.php?w=' + encodeURIComponent(w) + '&s=' + s;
119 XmlHttp.open('GET', url, true);
120 XmlHttp.setRequestHeader('If-Modified-Since', '0');
121 XmlLocked = true;
122 XmlHttp.onreadystatechange = function()
123 {
124 if (XmlHttp.readyState == 4)
125 {
126 XmlLocked = false;
127 if (XmlHttp.status == 200)
128 SetImageUrl(XmlHttp.responseText);
129 }
130 }
131 XmlHttp.send(null);
132 return true;
133}
134
135// Load style page
136function LoadStylePage(s, t, p)
137{
138 var nDiv = (s == 'mclick' ? 'HotList' : 'NewList');
139 var oDiv = document.getElementById(nDiv);
140
141 // send the request
142 if (!InitXmlHttp()) return;
143 SetProcMsg('样式风格加载中', false);
144 var url = '/index.php?x=page&s=' + s + '&t=' + encodeURIComponent(t) + '&p=' + p;
145 XmlHttp.open('GET', url, true);
146 XmlHttp.setRequestHeader('If-Modified-Since', '0');
147 XmlLocked = true;
148 XmlHttp.onreadystatechange = function()
149 {
150 if (XmlHttp.readyState == 4)
151 {
152 XmlLocked = false;
153 if (XmlHttp.status == 200)
154 {
155 oDiv.innerHTML = XmlHttp.responseText;
156 SetProcMsg('加载完毕', true);
157 }
158 }
159 }
160 XmlHttp.send(null);
161}
162
163// 复制图片到剪贴版
164function CopyImage(img)
165{
166 if (img.tagName != 'IMG') return;
167 if (typeof img.contentEditable == 'undefined') return;
168 if (!document.body.createControlRange) return;
169 var ctrl = document.body.createControlRange();
170 img.contentEditable = true;
171 ctrl.addElement(img);
172 ctrl.execCommand('Copy');
173 img.contentEditable = false;
174 alert('复制完成,到QQ对话框里按Ctrl-V就可以啦!');
175}
176
177// SetStyle
178function SetStyle(k,j,m)
179{
180 var es = document.zform.elements;
181 var en = document.zform.elements.length;
182 var ev = k + '' + j;
183 for (var i = 0; i < en; i++)
184 {
185 if (es[i].type != 'radio') continue;
186 if (es[i].value == ev)
187 {
188 es[i].checked = true;
189 break;
190 }
191 }
192 document.zform.s.value = k;
193 document.zform.m.value = m;
194 document.zform.w.focus();
195}
196
197// Zoom out the demo Image if it was zoom in
198function OutDemo(img)
199{
200 if (navigator.appVersion.indexOf("MSIE") == -1) return;
201 var demo = document.getElementById('DemoImg2');
202 demo.style.display = 'none';
203}
204
205function OverDemo(img)
206{
207 if (navigator.appVersion.indexOf("MSIE") == -1) return;
208 if (img.alt == '') return;
209
210 var demo = document.getElementById('DemoImg2');
211 demo.style.display = '';
212 var ex, ey;
213 var jmg = demo.childNodes[0];
214 jmg.src = img.src;
215
216 ex = document.body.scrollLeft + window.event.clientX;
217 ey = document.body.scrollTop + window.event.clientY - jmg.height - 20;
218 demo.style.left = String(ex) + 'px';
219 demo.style.top = String(ey) + 'px';
220}
221
222// Init the page
223// 加载后自动选择缺省风格并将输入框激活
224function PageInit() {
225 document.zform.w.focus();
226 document.zform.w.onkeyup = function (e)
227 {
228 if (!e) { e = window.event; }
229 if (e.keyCode == 8) { HideDemo(); }
230 }
231}
232</script>
2// xmlhttp
3var XmlHttp = false;
4var XmlLocked = false;
5
6// init xmlhttp
7function InitXmlHttp()
8{
9 if (!XmlHttp)
10 {
11 try { XmlHttp = new ActiveXObject('Msxml1.XMLHTTP'); }
12 catch (e)
13 {
14 try { XmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); }
15 catch (e) { XmlHttp = false; }
16 }
17 if (!XmlHttp && (typeof XMLHttpRequest != 'undefined'))
18 XmlHttp = new XMLHttpRequest();
19 if (!XmlHttp)
20 {
21 alert('抱歉您的浏览器不支持 XmlHttp 对像, 彩字制造失败.');
22 return false;
23 }
24 }
25
26 // lock check
27 if (XmlLocked == true)
28 {
29 alert('XmlHttp 某一次操作还没有完成, 请稍候啦.');
30 return false;
31 }
32 return true;
33}
34
35// 取得图片
36function GetImage(form)
37{
38 var text = form.w.value;
39 var style = form.s.value;
40 var maxword = parseInt(form.m.value);
41 if (text == '')
42 {
43 alert('总该说点什么吧?');
44 form.w.focus();
45 }
46 else if (text.length > maxword)
47 {
48 alert('抱歉,此风格最多' + maxword + '字');
49 form.w.value = form.w.value.substring(0,maxword);
50 form.w.focus();
51 }
52 else
53 {
54 SetProcMsg('请稍候', false);
55 SendImageRequest(text, style);
56 document.getElementById('DemoDiv').style.display = '';
57 document.getElementById('DemoImg').src = 'img/title_wait.gif';
58 document.getElementById('DemoImg').title = text;
59 form.w.focus();
60 }
61}
62// 修改值时要隐藏
63function HideDemo()
64{
65 document.getElementById('DemoDiv').style.display = 'none';
66}
67
68// 复制地址值
69function CopyValue(input)
70{
71 input.select();
72 window.clipboardData.setData('text', input.value);
73 alert('已经拷入剪贴板!');
74}
75
76// 设定执行说明
77function SetProcMsg(msg, nr)
78{
79 if (msg != '' && nr) { setTimeout('SetProcMsg("",false)', 3000); }
80 document.getElementById('ProcMsg').innerHTML = msg;
81}
82
83// 图片地址回调
84function SetImageUrl(str)
85{
86 //SendImageRequest
87 var rtype = str.substring(0,2);
88 var rdata = str.substring(4);
89 if (rtype != 'OK')
90 {
91 alert(rdata);
92 HideDemo();
93 SetProcMsg('太遗憾了', true);
94 }
95 else
96 {
97 var form = document.zform;
98 var url = rdata.substring(2);
99 url = url.replace(/\+/, '%20');
100 form.t.value = 'http://img2.ziq.com/' + url;
101 form.b.value = '[img]' + form.t.value + '[/img]';
102 document.getElementById('DemoImg').src = url;
103
104 // mmslink
105 var mlink = 'http://tlt.7town.com/ZComImgDIY/step2.asp?imageUrl=';
106 mlink += encodeURIComponent(form.t.value) + '&uid=20398&a=&b=&c=&d=&e=&f=';
107 document.getElementById("MmsLink").href = mlink;
108 SetProcMsg('祝贺您!!!', true);
109 }
110}
111
112// 提交图片申请
113function SendImageRequest(w, s)
114{
115 if (!InitXmlHttp()) return false;
116
117 // send the request
118 var url = 'm.php?w=' + encodeURIComponent(w) + '&s=' + s;
119 XmlHttp.open('GET', url, true);
120 XmlHttp.setRequestHeader('If-Modified-Since', '0');
121 XmlLocked = true;
122 XmlHttp.onreadystatechange = function()
123 {
124 if (XmlHttp.readyState == 4)
125 {
126 XmlLocked = false;
127 if (XmlHttp.status == 200)
128 SetImageUrl(XmlHttp.responseText);
129 }
130 }
131 XmlHttp.send(null);
132 return true;
133}
134
135// Load style page
136function LoadStylePage(s, t, p)
137{
138 var nDiv = (s == 'mclick' ? 'HotList' : 'NewList');
139 var oDiv = document.getElementById(nDiv);
140
141 // send the request
142 if (!InitXmlHttp()) return;
143 SetProcMsg('样式风格加载中', false);
144 var url = '/index.php?x=page&s=' + s + '&t=' + encodeURIComponent(t) + '&p=' + p;
145 XmlHttp.open('GET', url, true);
146 XmlHttp.setRequestHeader('If-Modified-Since', '0');
147 XmlLocked = true;
148 XmlHttp.onreadystatechange = function()
149 {
150 if (XmlHttp.readyState == 4)
151 {
152 XmlLocked = false;
153 if (XmlHttp.status == 200)
154 {
155 oDiv.innerHTML = XmlHttp.responseText;
156 SetProcMsg('加载完毕', true);
157 }
158 }
159 }
160 XmlHttp.send(null);
161}
162
163// 复制图片到剪贴版
164function CopyImage(img)
165{
166 if (img.tagName != 'IMG') return;
167 if (typeof img.contentEditable == 'undefined') return;
168 if (!document.body.createControlRange) return;
169 var ctrl = document.body.createControlRange();
170 img.contentEditable = true;
171 ctrl.addElement(img);
172 ctrl.execCommand('Copy');
173 img.contentEditable = false;
174 alert('复制完成,到QQ对话框里按Ctrl-V就可以啦!');
175}
176
177// SetStyle
178function SetStyle(k,j,m)
179{
180 var es = document.zform.elements;
181 var en = document.zform.elements.length;
182 var ev = k + '' + j;
183 for (var i = 0; i < en; i++)
184 {
185 if (es[i].type != 'radio') continue;
186 if (es[i].value == ev)
187 {
188 es[i].checked = true;
189 break;
190 }
191 }
192 document.zform.s.value = k;
193 document.zform.m.value = m;
194 document.zform.w.focus();
195}
196
197// Zoom out the demo Image if it was zoom in
198function OutDemo(img)
199{
200 if (navigator.appVersion.indexOf("MSIE") == -1) return;
201 var demo = document.getElementById('DemoImg2');
202 demo.style.display = 'none';
203}
204
205function OverDemo(img)
206{
207 if (navigator.appVersion.indexOf("MSIE") == -1) return;
208 if (img.alt == '') return;
209
210 var demo = document.getElementById('DemoImg2');
211 demo.style.display = '';
212 var ex, ey;
213 var jmg = demo.childNodes[0];
214 jmg.src = img.src;
215
216 ex = document.body.scrollLeft + window.event.clientX;
217 ey = document.body.scrollTop + window.event.clientY - jmg.height - 20;
218 demo.style.left = String(ex) + 'px';
219 demo.style.top = String(ey) + 'px';
220}
221
222// Init the page
223// 加载后自动选择缺省风格并将输入框激活
224function PageInit() {
225 document.zform.w.focus();
226 document.zform.w.onkeyup = function (e)
227 {
228 if (!e) { e = window.event; }
229 if (e.keyCode == 8) { HideDemo(); }
230 }
231}
232</script>