<?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>小山博客</title>
	<atom:link href="http://www.izmax.cn/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.izmax.cn</link>
	<description>css,JavaScript等web技术分享博客</description>
	<lastBuildDate>Sat, 31 Jul 2010 15:33:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>第十期《web标准交流会》JavaScript技术分享(getJSON)</title>
		<link>http://www.izmax.cn/?p=351</link>
		<comments>http://www.izmax.cn/?p=351#comments</comments>
		<pubDate>Sat, 31 Jul 2010 14:23:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web标准]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=351</guid>
		<description><![CDATA[这次是我第四次参加《web标准交流会》,因为最近工作挺忙，所以没能及时关注WEB标准交流会网站,当我看到本期话题《前端工程师应该如何学习javascript》时，眼前一亮。由于前几次话题大多是分享工作中部门之间配合,而很少有这种纯技术的话题(也可能是我参加的次数不多，错过了以前的技术讨论). 这次交流会解决了我最近工作中遇到的一个JavaScript跨域调用数据的问题。就我个人来说，平时工作中使用Ajax无非以下几种: 1.基本调用(代码片段): var request=new XMLHttpRequest(); //仅作参考 request.open(&#8220;GET&#8221;,url,true); request.onreadystatechange=function(){&#8230;}; request.send(&#8221;); 2.使用jQuery框架(代码片段): $.ajax({ type:&#8221;GET&#8221;, url:&#8221;", data:{}, beforeSend:function(){&#8230;}, success:function(){&#8230;.}, error:function(){&#8230;} }) 3.jQuery的$.getJSON(url,data,callback)，即JSONP技术; 和上面2相比差异如下: 优点 ：跨域； 缺点：不提供错误处理，如果动态插入的代码正常运行，你可以得到返回，但是如果失败了，那么什么都不会发生。你无法获得一个404的错误，也不能取消这个请求。我处理的方式可见$.getJSON的错误处理(原创) 重点来了: 虽然上面这些方法在处理常规的交互已经足够了,不过我有个需求:不使用jQuery框架实现JSONP功能。其实这个从原理上来讲写起来并不难, 下面是我的最初版: 定义函数: function getJSON ( url , func ){ if (! document . getElementById ){ return false ; } if ( document . getElementById ( &#8221;jsonscript&#8221; )){ var oldscript = document . getElementsByTagName ( &#8221;script&#8221; ); for ( var i = 0 ; i &#60; oldscript . length ; i ++){ if ( oldscript [ i ]. getAttribute ( &#8221;src&#8221; ) == url ) { oldscript . parentNode . removeChild ( oldscript ); } } } var script = document . createElement ( &#8221;script&#8221; ); script . setAttribute ( &#8221;src&#8221; , url ); script . setAttribute ( &#8221;id&#8221; , &#8221;jsonscript&#8221; ); document . getElementsByTagName ( &#8221;head&#8221; )[ 0 ]. appendChild ( script ); } 回调函数: function parseDZList ( json ){ var show = document . getElementById ( &#8221;show&#8221; ); var Status = json . StatusInfo . Status ; var items = json . Items ; for ( var i = 0 ; i &#60; items . length ; i ++){ show . innerHTML += items [ i ]. ZName ; } } 页面调用: [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>这次是我第四次参加《web标准交流会》,因为最近工作挺忙，所以没能及时关注<a href="http://www.w3ctech.com/">WEB标准交流会网站</a>,当我看到本期话题《前端工程师应该如何学习javascript》时，眼前一亮。由于前几次话题大多是分享工作中部门之间配合,而很少有这种纯技术的话题(也可能是我参加的次数不多，错过了以前的技术讨论).</p>
<p>这次交流会解决了我最近工作中遇到的一个<strong>JavaScript跨域调用数据</strong>的问题。就我个人来说，平时工作中使用Ajax无非以下几种:</p>
<p>1.基本调用(代码片段):</p>
<blockquote><p>var request=new XMLHttpRequest(); //仅作参考</p>
<p>request.open(&#8220;GET&#8221;,url,true);</p>
<p>request.onreadystatechange=function(){&#8230;};</p>
<p>request.send(&#8221;);</p></blockquote>
<p>2.使用jQuery框架(代码片段):</p>
<p>$.ajax({</p>
<p>type:&#8221;GET&#8221;,</p>
<p>url:&#8221;",</p>
<p>data:{},</p>
<p>beforeSend:function(){&#8230;},</p>
<p>success:function(){&#8230;.},</p>
<p>error:function(){&#8230;}</p>
<p>})</p>
<p>3.jQuery的$.getJSON(url,data,callback)，即JSONP技术;</p>
<p>和上面2相比差异如下:</p>
<p>优点 ：跨域；</p>
<p>缺点：不提供错误处理，如果动态插入的代码正常运行，你可以得到返回，但是如果失败了，那么什么都不会发生。你无法获得一个404的错误，也不能取消这个请求。我处理的方式可见<a href="http://www.izmax.cn/?p=332">$.getJSON的错误处理(原创)</a></p>
<hr />重点来了:</p>
<p>虽然上面这些方法在处理常规的交互已经足够了,不过我有个需求:不使用jQuery框架实现JSONP功能。其实这个从原理上来讲写起来并不难,</p>
<p><strong>下面是我的最初版:</strong></p>
<p><strong>定义函数:</strong></p>
<p>function getJSON ( url , func ){</p>
<div>if (! document . getElementById ){</div>
<div>return false ;</div>
<div>}</div>
<div>if ( document . getElementById ( &#8221;jsonscript&#8221; )){</div>
<div>var oldscript = document . getElementsByTagName ( &#8221;script&#8221; );</div>
<div>for ( var i = 0 ; i &lt; oldscript . length ; i ++){</div>
<div>if ( oldscript [ i ]. getAttribute ( &#8221;src&#8221; ) == url ) {</div>
<div>oldscript . parentNode . removeChild ( oldscript );</div>
<div>}</div>
<div>}</div>
<div>}</div>
<div>var script = document . createElement ( &#8221;script&#8221; );</div>
<div>script . setAttribute ( &#8221;src&#8221; , url );</div>
<div>script . setAttribute ( &#8221;id&#8221; , &#8221;jsonscript&#8221; );</div>
<div>document . getElementsByTagName ( &#8221;head&#8221; )[ 0 ]. appendChild ( script );</div>
<p>}</p>
<p><strong>回调函数:</strong></p>
<div>function parseDZList ( json ){</div>
<div>var show = document . getElementById ( &#8221;show&#8221; );</div>
<div>var Status = json . StatusInfo . Status ;</div>
<div>var items = json . Items ;</div>
<div>for ( var i = 0 ; i &lt; items . length ; i ++){</div>
<div>show . innerHTML += items [ i ]. ZName ;</div>
<div>}</div>
<p>}</p>
<p><strong>页面调用:</strong></p>
<div>window.onload = function (){</div>
<div>getJSON ( &#8221;http://api.zhui.cn/content/ZIDList.json?jsoncallback=parseDZList&#8221; );</div>
<p>}</p>
<p>虽然可以实现效果,但是代码凌乱，不便重用。</p>
<hr /><strong>今天在会上请教JavaScript大牛后代码如下</strong>:</p>
<p><strong>定义函数:</strong></p>
<p>function getJSON(url, func){</p>
<p>if (!document.getElementById) {</p>
<p>return false;</p>
<p>}</p>
<p>if (document.getElementById(&#8220;jsonscript&#8221;)) {</p>
<p>var oldscript = document.getElementsByTagName(&#8220;script&#8221;);</p>
<p>for (var i = 0; i &lt; oldscript.length; i++) {</p>
<p>if (oldscript[i].getAttribute(&#8220;src&#8221;) == url) {</p>
<p>oldscript.parentNode.removeChild(oldscript);</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>var script = document.createElement(&#8220;script&#8221;);</p>
<p>var rnd=parseInt(Math.random()*1e8);</p>
<p>url+=&#8221;?jsoncallback=callback&#8221;+rnd;</p>
<p>script.setAttribute(&#8220;src&#8221;, url);</p>
<p>window["callback"+rnd]=func;</p>
<p>script.setAttribute(&#8220;id&#8221;, &#8220;jsonscript&#8221;);</p>
<p>document.getElementsByTagName(&#8220;head&#8221;)[0].appendChild(script);</p>
<p>}</p>
<p><strong>回调函数:</strong></p>
<p>function parseDZList(json){</p>
<p>var show = document.getElementById(&#8220;show&#8221;);</p>
<p>var Status = json.StatusInfo.Status;</p>
<p>var items = json.Items;</p>
<p>for (var i = 0; i &lt; items.length; i++) {</p>
<p>var ZIMG=items[i].ZIMG</p>
<p>ZIMG=ZIMG.replace(&#8220;{0}&#8221;,&#8221;64&#215;64&#8243;)</p>
<p>show.innerHTML += &#8221;</p>
<li><img src="http://showfan.cn/+ZIMG+" alt="" />&#8220;+items[i].ZName+&#8221;</li>
<p>&#8220;;</p>
<p>}</p>
<p>}</p>
<p><strong>页面调用:</strong></p>
<p>window.onload = function(){</p>
<p>getJSON(&#8220;http://api.zhui.cn/content/ZIDList.json&#8221;,parseDZList);</p>
<p>}</p>
<p>后来在群里分享时Along对var rnd=parseInt(Math.random()*1e8)提出自己的观点，并提示可以用生成数组的方式来处理,更大程度上避免了碰撞.不过还好这个只是为了避免缓存，不用太花心思.为了方便我还是使用了数组。</p>
<p>然后小肥猪(冯恒)，在群里发了一段代码：</p>
<p>$getJSON = function(url,fun){</p>
<p>var s  = document.createElement(&#8216;script&#8217;);</p>
<p>s.src = url;</p>
<p>var callback = &#8216;callback&#8217;+ (+new Date());</p>
<p>window[callback] = fun;</p>
<p>document.body.appendChild(s);</p>
<p>}</p>
<p>这个主要是改良了随机数(小小提示下哦,这个代码没有实现JSONP的功能哦);</p>
<hr /><strong> </strong></p>
<p><strong><strong>于是融合上面的代码后最终代码如下:</strong></strong></p>
<p><strong><strong>定义函数:</strong></strong></p>
<p><strong><span style="font-family: SimSun;">function getJSON(url, func){</span></strong></p>
<p><strong><span style="font-family: SimSun;"> if (!document.getElementById) {</span></p>
<p><span style="font-family: SimSun;"> return false;</span></p>
<p><span style="font-family: SimSun;"> }</span></p>
<p><span style="font-family: SimSun;"> if (document.getElementById(&#8220;jsonscript&#8221;)) {</span></p>
<p><span style="font-family: SimSun;"> var oldscript = document.getElementsByTagName(&#8220;script&#8221;);</span></p>
<p><span style="font-family: SimSun;"> for (var i = 0; i &lt; oldscript.length; i++) {</span></p>
<p><span style="font-family: SimSun;"> if (oldscript[i].getAttribute(&#8220;src&#8221;) == url) {</span></p>
<p><span style="font-family: SimSun;"> oldscript.parentNode.removeChild(oldscript);</span></p>
<p><span style="font-family: SimSun;"> }</span></p>
<p><span style="font-family: SimSun;"> }</span></p>
<p><span style="font-family: SimSun;"> }</span></p>
<p><span style="font-family: SimSun;"> var script = document.createElement(&#8220;script&#8221;);</span></p>
<p><span style="font-family: SimSun;"> var callback = &#8216;callback&#8217;+ (+new Date());</span></p>
<p><span style="font-family: SimSun;"> url+=&#8221;?jsoncallback=&#8221;+callback;</span></p>
<p><span style="font-family: SimSun;"> script.setAttribute(&#8220;src&#8221;, url);</span></p>
<p><span style="font-family: SimSun;"> window[callback]=func;</span></p>
<p><span style="font-family: SimSun;"> script.setAttribute(&#8220;id&#8221;, &#8220;jsonscript&#8221;);</span></p>
<p><span style="font-family: SimSun;"> document.getElementsByTagName(&#8220;head&#8221;)[0].appendChild(script);</span></p>
<p><span style="font-family: SimSun;"> }</span></p>
<p><strong>回调函数:</strong></p>
<p><span style="font-family: SimSun;">function parseDZList(json){</span></p>
<p><span style="font-family: SimSun;"> var show = document.getElementById(&#8220;show&#8221;);</span></p>
<p><span style="font-family: SimSun;"> var Status = json.StatusInfo.Status;</span></p>
<p><span style="font-family: SimSun;"> var items = json.Items;</span></p>
<p><span style="font-family: SimSun;"> for (var i = 0; i &lt; items.length; i++) {</span></p>
<p><span style="font-family: SimSun;"> var ZIMG=items[i].ZIMG</span></p>
<p><span style="font-family: SimSun;"> ZIMG=ZIMG.replace(&#8220;{0}&#8221;,&#8221;64&#215;64&#8243;)</span></p>
<p><span style="font-family: SimSun;"> show.innerHTML += &#8220;&lt;li&gt;&lt;img src=&#8221;+ZIMG+&#8221; /&gt;&#8221;+items[i].ZName+&#8221;&lt;/li&gt;&#8221;;</span></p>
<p><span style="font-family: SimSun;"> }</span></p>
<p><span style="font-family: SimSun;"> }</span></p>
<p><strong>页面调用:</strong></p>
<p><span style="font-family: SimSun;">window.onload = function(){</span></p>
<p><span style="font-family: SimSun;"> getJSON(&#8220;http://api.zhui.cn/content/ZIDList.json&#8221;,parseDZList);</span></p>
<p><span style="font-family: SimSun;"> }</span></p>
<p>终于松了一口气~<img src="file:///C:/Users/Administrator/AppData/Local/Temp/EvernoteCopyBuffer/96792b0e-0461-42d8-b69e-f097dc9d564f.gif" alt="" /><img src="http://showfan.cn/editor/plugins/emoticons/21.gif" border="0" alt="" /></p>
<h2>演示地址:<a href="http://www.showfan.cn/demo/getJSON.html" target="_blank">http://www.showfan.cn/demo/getJSON.html</a></h2>
<p></strong></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=351</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JavaScript缓动效果加强版（一）</title>
		<link>http://www.izmax.cn/?p=345</link>
		<comments>http://www.izmax.cn/?p=345#comments</comments>
		<pubDate>Tue, 25 May 2010 04:41:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=345</guid>
		<description><![CDATA[在上一篇简单的JavaScript缓动效果的效果上加入暂停和继续； 重点在于：暂停时记录一下当前的动作，留着点击继续用 DEMO：http://showfan.cn/demo/moveElement2.html]]></description>
			<content:encoded><![CDATA[<p>在上一篇<a href="http://showfan.cn/share.php?pid=461" target="_blank">简单的JavaScript缓动效果</a>的效果上加入暂停和继续；</p>
<p>重点在于：暂停时记录一下当前的动作，留着点击继续用</p>
<p>DEMO：<a href="http://showfan.cn/demo/moveElement2.html" target="_blank">http://showfan.cn/demo/moveElement2.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=345</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>简单的JavaScript缓动效果</title>
		<link>http://www.izmax.cn/?p=342</link>
		<comments>http://www.izmax.cn/?p=342#comments</comments>
		<pubDate>Mon, 24 May 2010 16:14:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=342</guid>
		<description><![CDATA[DEMO：http://showfan.cn/demo/moveElement.html 难点:计算运动过程中的位移 function moveElement(elementID,final_x,final_y,interval){ if(!document.getElementById) return false; if(!document.getElementById(elementID)) return false; var elem=document.getElementById(elementID); var xpos=parseInt(elem.style.left); var ypos=parseInt(elem.style.top); if(xpos==final_x&#38;&#38;ypos==final_y){ return false; } if(xpos var dist=Math.ceil((final_x-xpos)/10) xpos=xpos+dist; } if(xpos&#62;final_x){ var dist=Math.ceil((xpos-final_x)/10) xpos=xpos-dist; } if(ypos var dist=Math.ceil((final_y-ypos)/10) ypos=ypos+dist; } if(ypos&#62;final_y){ var dist=Math.ceil((ypos-final_y)/10) ypos=ypos-dist; } elem.style.left=xpos+&#8221;px&#8221;; elem.style.top=ypos+&#8221;px&#8221;; var repeat=&#8221;moveElement(&#8216;&#8221;+elementID+&#8221;&#8216;,&#8221;+final_x+&#8221;,&#8221;+final_y+&#8221;,&#8221;+interval+&#8221;)&#8221;; timer=setTimeout(repeat,interval); }]]></description>
			<content:encoded><![CDATA[<p>DEMO：<a href="http://showfan.cn/demo/moveElement.html" target="_blank">http://showfan.cn/demo/moveElement.html</a></p>
<p>难点:计算运动过程中的位移</p>
<p>function  moveElement(elementID,final_x,final_y,interval){<br />
if(!document.getElementById) return false;<br />
if(!document.getElementById(elementID)) return false;<br />
var elem=document.getElementById(elementID);<br />
var xpos=parseInt(elem.style.left);<br />
var ypos=parseInt(elem.style.top);<br />
if(xpos==final_x&amp;&amp;ypos==final_y){<br />
return false;<br />
}<br />
if(xpos<br />
var dist=Math.ceil((final_x-xpos)/10)<br />
xpos=xpos+dist;<br />
}<br />
if(xpos&gt;final_x){<br />
var dist=Math.ceil((xpos-final_x)/10)<br />
xpos=xpos-dist;<br />
}<br />
if(ypos<br />
var dist=Math.ceil((final_y-ypos)/10)<br />
ypos=ypos+dist;<br />
}<br />
if(ypos&gt;final_y){<br />
var dist=Math.ceil((ypos-final_y)/10)<br />
ypos=ypos-dist;<br />
}</p>
<p>elem.style.left=xpos+&#8221;px&#8221;;<br />
elem.style.top=ypos+&#8221;px&#8221;;<br />
var repeat=&#8221;moveElement(&#8216;&#8221;+elementID+&#8221;&#8216;,&#8221;+final_x+&#8221;,&#8221;+final_y+&#8221;,&#8221;+interval+&#8221;)&#8221;;<br />
timer=setTimeout(repeat,interval);<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=342</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>aptana 不能安装nokia wrt plugin的解决办法</title>
		<link>http://www.izmax.cn/?p=339</link>
		<comments>http://www.izmax.cn/?p=339#comments</comments>
		<pubDate>Fri, 21 May 2010 05:10:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=339</guid>
		<description><![CDATA[这个方法很早之前就在用了，当时以为这只是个小bug，以为Nokia会及时修复，不过到现在aptana装Nokia wrt插件还是报错。就写上来供大家参考: 当用正常方法安装失败的情况下情使用下面的方法： 第一步: 打开aptana-&#62;help-&#62;Install New Software 第二步: 在Work with处输入:http://www.showfan.cn/com.nokia.wrt.2.1.0.v20090707223056 第三步: 取消选中&#8221;Group items by catagory&#8221;这一项,这时会列出可用的插件， 第四步: 然后选中&#8221;Nokia Web Runtime plug-in&#8230;..&#8221;这一项,继续&#8221;下一步&#8221; 第五步，默认安装直到完成]]></description>
			<content:encoded><![CDATA[<p>这个方法很早之前就在用了，当时以为这只是个小bug，以为Nokia会及时修复，不过到现在aptana装Nokia wrt插件还是报错。就写上来供大家参考:</p>
<p>当用正常方法安装失败的情况下情使用下面的方法：</p>
<p>第一步:</p>
<p>打开aptana-&gt;help-&gt;Install New Software</p>
<p><img src="http://showfan.cn/gallery/upload/2010052175067.jpg" alt="" /></p>
<p>第二步:</p>
<p>在Work with处输入:<a href="http://www.showfan.cn/com.nokia.wrt.2.1.0.v20090707223056/">http://www.showfan.cn/com.nokia.wrt.2.1.0.v20090707223056</a></p>
<p><img src="http://showfan.cn/gallery/upload/2010052125301.jpg" alt="" /></p>
<p>第三步:</p>
<p>取消选中&#8221;Group items by catagory&#8221;这一项,这时会列出可用的插件，</p>
<p><img src="http://showfan.cn/gallery/upload/2010052122494.jpg" alt="" /></p>
<p>第四步:</p>
<p>然后选中&#8221;Nokia Web Runtime plug-in&#8230;..&#8221;这一项,继续&#8221;下一步&#8221;</p>
<p><img src="http://showfan.cn/gallery/upload/2010052156010.jpg" alt="" /></p>
<p>第五步，默认安装直到完成</p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=339</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>啊哈，偶的佳能IXUS中奖了</title>
		<link>http://www.izmax.cn/?p=335</link>
		<comments>http://www.izmax.cn/?p=335#comments</comments>
		<pubDate>Thu, 20 May 2010 15:33:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[关于站长]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=335</guid>
		<description><![CDATA[期待已久的开奖日终于到来，偶滴大名也在获奖名单上面啊~~只不过不知道是几等奖，真希望是一等奖哇(*^__^*) …… ~~~估计是三等奖~~~]]></description>
			<content:encoded><![CDATA[<p>期待已久的开奖日终于到来，偶滴大名也在获奖名单上面啊~~只不过不知道是几等奖，真希望是一等奖哇(*^__^*) ……</p>
<p>~~~估计是三等奖~~~</p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=335</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>$.getJSON的错误处理(原创)</title>
		<link>http://www.izmax.cn/?p=332</link>
		<comments>http://www.izmax.cn/?p=332#comments</comments>
		<pubDate>Mon, 17 May 2010 14:03:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=332</guid>
		<description><![CDATA[$.getJSON是个好东西，其亮点在于可以跨域调用数据和解析数据简单,这让很多的jQueryer乐此不彼. 好了废话不多说，进入正文: 1.设置加载图片&#60;div id=&#8221;loading&#8221;&#62;&#60;img src=&#8221;m/loading.gif&#8221;/&#62;&#60;/div&#62; 2.调用数据前 setTimeout(function(){ if($(&#8220;#loading&#8221;).is(&#8220;:visible&#8221;)){ $(&#8220;#loading&#8221;).empty().append(&#8220;&#60;p&#62;&#8221;+timeoutStr+&#8221;&#60;br/&#62;&#60;a href=&#8217;javascript:void(0)&#8217; onclick=&#8217;getZhuiList()&#8217;&#62;&#60;img src=&#8217;m/refresh.png&#8217;/&#62;刷新&#60;/a&#62;&#60;/p&#62;&#8221;); return false; } },timeout) 3.载入数据后 $.getJSON(url, function(msg){ $(&#8220;#loading&#8221;).hide(); &#8230;.. }) 原理: 在载入数据前加个标记，我这里用的是一个loading图片，其实也可以用变量来代替，然后执行$.getJSON，这里分两种情况:一种是加载成功，正常执行$.getJSON里面的代码；第二个是加载失败，不返回任何信息。所以，我把设置loading图片隐藏的代码放在加载成功时执行。当加载失败时，loading图片是不会被隐藏的(废话~)。后面的我们就可以做主了，任意设置一个超时时间，用settimeout来检查有没有执行隐藏loading的代码，具体方式是：图片是否隐藏。若图片没有隐藏，OK，我们的目的达到了，可以给用户一个提示,比如重试啊之类的! 后话: $.getJSON很傻很天真，所以它忽略了错误，当你用它来获取一个404页面的时候，你会发现它不会返回信息( 其实经过测试发现，有返回值的   var url=""; var x=$.getJSON(url, function(msg){      alert(msg); }) alert(x.readyState) 实验结果，在Safari下 当URL正常，载入数据也正常时，第一个alert出来的是Object,第二个不弹出 当URL为404时，Firefox下,第一个alert不弹出，第二个alert弹出1;IE下没弹出信息 待测试&#8230; ),]]></description>
			<content:encoded><![CDATA[<p>$.getJSON是个好东西，其亮点在于<strong>可以跨域调用数据</strong>和<strong>解析数据简单,</strong>这让很多的jQueryer乐此不彼.</p>
<p>好了废话不多说，进入正文:</p>
<p>1.设置加载图片&lt;div id=&#8221;loading&#8221;&gt;&lt;img src=&#8221;m/loading.gif&#8221;/&gt;&lt;/div&gt;</p>
<p>2.调用数据前</p>
<div id="_mcePaste">setTimeout(function(){</div>
<div id="_mcePaste">if($(&#8220;#loading&#8221;).is(&#8220;:visible&#8221;)){</div>
<div id="_mcePaste">$(&#8220;#loading&#8221;).empty().append(&#8220;&lt;p&gt;&#8221;+timeoutStr+&#8221;&lt;br/&gt;&lt;a href=&#8217;javascript:void(0)&#8217; onclick=&#8217;getZhuiList()&#8217;&gt;&lt;img src=&#8217;m/refresh.png&#8217;/&gt;刷新&lt;/a&gt;&lt;/p&gt;&#8221;);</div>
<div id="_mcePaste">return false;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">},timeout)</div>
<p>3.载入数据后</p>
<p>$.getJSON(url, function(msg){</p>
<p>$(&#8220;#loading&#8221;).hide();</p>
<p>&#8230;..</p>
<p>})</p>
<h2 style="font-size: 1.5em;"><strong><span style="color: #3366ff;">原理:</span></strong></h2>
<p>在载入数据前加个标记，我这里用的是一个loading图片，其实也可以用变量来代替，然后执行$.getJSON，这里分两种情况:一种是加载成功，正常执行$.getJSON里面的代码；第二个是加载失败，不返回任何信息。所以，我把设置loading图片隐藏的代码放在加载成功时执行。当加载失败时，loading图片是不会被隐藏的(废话~)。后面的我们就可以做主了，任意设置一个超时时间，用settimeout来检查有没有执行隐藏loading的代码，具体方式是：图片是否隐藏。若图片没有隐藏，OK，我们的目的达到了，可以给用户一个提示,比如重试啊之类的!</p>
<h2><strong><span style="color: #3366ff;">后话:</span></strong></h2>
<p>$.getJSON很傻很天真，所以它忽略了错误，当你用它来获取一个404页面的时候，你会发现它不会返回信息(</p>
<p><span style="color: #ff0000;">其实经过测试发现，有返回值的</span></p>
<pre><span style="color: #ff0000;">  var url="";</span></pre>
<pre><span style="color: #ff0000;">var x=$.getJSON(url, function(msg){</span></pre>
<pre><span style="color: #ff0000;">     alert(msg);</span></pre>
<pre><span style="color: #ff0000;">})</span></pre>
<pre><span style="color: #ff0000;">alert(x.readyState)</span></pre>
<p><span style="color: #ff0000;"><br />
</span></p>
<div><span style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"><span style="color: #ff0000;"> 实验结果，在Safari下</span></span></div>
<div><span style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"><span style="color: #ff0000;">当URL正常，载入数据也正常时，第一个alert出来的是Object,第二个不弹出</span></span></div>
<div><span style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"><span style="color: #ff0000;">当URL为404时，Firefox下,第一个alert不弹出，第二个alert弹出1;IE下没弹出信息</span></span></div>
<p>待测试&#8230;</p>
<p>),</p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=332</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>恭喜本博客PR值升到2</title>
		<link>http://www.izmax.cn/?p=325</link>
		<comments>http://www.izmax.cn/?p=325#comments</comments>
		<pubDate>Sat, 10 Apr 2010 14:03:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[关于站长]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=325</guid>
		<description><![CDATA[哈，今天突然查了一下本博客的PR值。不看不知道，一看吓一跳，PR值为2，怕是搞错了，就到几个查PR值的网站分别查了一下，确实是这样。 是这样，由于本博客的虚拟主机不稳定，在之前查PR的时候一直是0，就没怎么管，没想PR会增加。 无论如何，自我恭喜一下]]></description>
			<content:encoded><![CDATA[<p>哈，今天突然查了一下本博客的PR值。不看不知道，一看吓一跳，PR值为2，怕是搞错了，就到几个查PR值的网站分别查了一下，确实是这样。</p>
<p>是这样，由于本博客的虚拟主机不稳定，在之前查PR的时候一直是0，就没怎么管，没想PR会增加。</p>
<p>无论如何，自我恭喜一下<a href="http://www.izmax.cn/wp-content/uploads/2010/04/big_smile.png"><img class="alignnone size-full wp-image-326" title="big_smile" src="http://www.izmax.cn/wp-content/uploads/2010/04/big_smile.png" alt="" width="128" height="128" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=325</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>$.ajax的错误处理</title>
		<link>http://www.izmax.cn/?p=323</link>
		<comments>http://www.izmax.cn/?p=323#comments</comments>
		<pubDate>Wed, 07 Apr 2010 14:32:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=323</guid>
		<description><![CDATA[jQuery中用Ajax时很方便的，大家都知道像下面的调用 $.ajax({ type:&#8221;GET&#8221;, url:&#8221;http://10.10.10.1&#8243;, dataType:&#8221;JSON&#8221;, beforeSend:function(){}, success:function(msg){alert(msg)}, error:function(){} }) 上面的error是处理错误的常用方法，但是当URL无法连接时，error就 不能正常处理了，用firebug调试的时候发现当Ajax请求超时时会报msg is null，于是在这个时候可以用msg-即返回的内容判断，试着修改一下代码: success:function(msg){ if(!msg){ alert(&#8220;未知错误!&#8221;) $(&#8220;.pop_inner h3&#8243;).html(&#8220;连接数据库失败!&#8221;);//例子 return false; } 可以正常处理错误]]></description>
			<content:encoded><![CDATA[<p>jQuery中用Ajax时很方便的，大家都知道像下面的调用</p>
<p>$.ajax({</p>
<p>type:&#8221;GET&#8221;,</p>
<p>url:&#8221;http://10.10.10.1&#8243;,</p>
<p>dataType:&#8221;JSON&#8221;,</p>
<p>beforeSend:function(){},</p>
<p>success:function(msg){alert(msg)},</p>
<p>error:function(){}</p>
<p>})</p>
<p>上面的error是处理错误的常用方法，但是当URL无法连接时，error就 不能正常处理了，用firebug调试的时候发现当Ajax请求超时时会报msg is  null，于是在这个时候可以用msg-即返回的内容判断，试着修改一下代码:</p>
<p>success:function(msg){</p>
<p>if(!msg){<br />
alert(&#8220;未知错误!&#8221;)<br />
$(&#8220;.pop_inner h3&#8243;).html(&#8220;连接数据库失败!&#8221;);//例子<br />
return false;</p>
<p>}</p>
<p>可以正常处理错误</p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=323</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>手动取消Ajax请求（jQuery篇）</title>
		<link>http://www.izmax.cn/?p=321</link>
		<comments>http://www.izmax.cn/?p=321#comments</comments>
		<pubDate>Sat, 03 Apr 2010 11:07:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=321</guid>
		<description><![CDATA[在执行Ajax请求的之后，在合适的时候清除请求很有必要。当用户想取消这次执行的时候，比如关闭模态窗口，作为开发人员来讲，隐藏窗口并不能真正的取消这个操作，应该从根本上取消这个请求： var request;//定义Ajax执行标记 request=$.ajax({ type:&#8221;GET&#8221;,url:&#8221;http://test.com/test.php&#8221;,&#8230; }) 用户取消时: if(request) { request.abort();}]]></description>
			<content:encoded><![CDATA[<p>在执行Ajax请求的之后，在合适的时候清除请求很有必要。当用户想取消这次执行的时候，比如关闭模态窗口，作为开发人员来讲，隐藏窗口并不能真正的取消这个操作，应该从根本上取消这个请求：</p>
<p>var request;//定义Ajax执行标记</p>
<p>request=$.ajax({</p>
<p>type:&#8221;GET&#8221;,url:&#8221;http://test.com/test.php&#8221;,&#8230;</p>
<p>})</p>
<p>用户取消时: if(request) { request.abort();}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=321</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>css表单聚焦效果</title>
		<link>http://www.izmax.cn/?p=314</link>
		<comments>http://www.izmax.cn/?p=314#comments</comments>
		<pubDate>Thu, 18 Mar 2010 09:28:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Css]]></category>

		<guid isPermaLink="false">http://www.izmax.cn/?p=314</guid>
		<description><![CDATA[其实主要是不会在切换选项的时候引起整块抖动，这也是我实现这个效果的初衷. demo:http://www.izmax.cn/demo/form_focus.html 可应用在:]]></description>
			<content:encoded><![CDATA[<p>其实主要是不会在切换选项的时候引起整块抖动，这也是我实现这个效果的初衷.</p>
<p>demo:<a href="http://www.izmax.cn/demo/form_focus.html" target="_blank">http://www.izmax.cn/demo/form_focus.html</a></p>
<p>可应用在:</p>
<p><img class="alignnone" title="追信gadget demo" src="http://www.izmax.cn/images/zhui_gadget_t.png" alt="" width="321" height="249" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.izmax.cn/?feed=rss2&amp;p=314</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
