<?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>Kej.tw Revisited &#187; 程式設計</title>
	<atom:link href="http://blog.kej.tw/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kej.tw</link>
	<description>一個懶鬼的部落格</description>
	<lastBuildDate>Wed, 27 Apr 2022 20:02:14 +0000</lastBuildDate>
	<language>zh-TW</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8.3</generator>
	<item>
		<title>jQuery 1.0.2</title>
		<link>http://blog.kej.tw/2006-10/12/jquery-102/</link>
		<comments>http://blog.kej.tw/2006-10/12/jquery-102/#comments</comments>
		<pubDate>Thu, 12 Oct 2006 14:37:27 +0000</pubDate>
		<dc:creator><![CDATA[Kej]]></dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://blog.kej.tw/2006-10/12/jquery-102/</guid>
		<description><![CDATA[手上的某個專案因為歷史的關係:?:，所以先後分別用了 prototype 跟 jQuery 兩個 JavaSc [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>手上的某個專案因為歷史的關係:?:，所以先後分別用了 <a href="http://prototype.conio.net/">prototype</a> 跟 <a href="http://jquery.com/">jQuery</a> 兩個 JavaScript library，今天想了一下，還是決定統一用一個 library 就好了；由於 jQuery 看起來較輕薄短小（其實 <a href="http://dean.edwards.name/packer/">pack</a> 起來後兩個差不多大），加上 Chainable、支援 XPath 等一些像我這種懶人喜愛的特性的緣故，決定全部使用 jQuery。</p>
<p>程式都改完、測試好之後才想到該去 <a href="http://jquery.com/">jQuery 官網</a>看看，發現 10/9 剛發佈了新的 1.0.2 版，於是就下載回來更新（之前是用 1.0.1 版），沒想到一更新之後所有 $.ajax callback 的部份全都失效了，查了一下 <a href="http://jquery.com/api/">API</a> 發現原來在 <a href="http://jquery.com/api/#$.ajax">$.ajax</a> 的地方是這樣寫的：</p>
<blockquote><p>(Function) error &#8211; A function to be called if the request fails. The function gets passed two arguments: The <strong>XMLHttpRequest object</strong> and a string describing the type of error that occurred.</p>
<p>(Function) success &#8211; A function to be called if the request succeeds. The function gets passed one argument: The <strong style="color:#f00;">data returned from the server</strong>, formatted according to the &#8216;dataType&#8217; parameter.</p>
<p>(Function) complete &#8211; A function to be called when the request finishes. The function gets passed two arguments: The <strong>XMLHttpRequest object</strong> and a string describing the type the success of the request.</p></blockquote>
<p>而我的程式在 success 時的 callback function 卻也是以回傳一個 XMLHttpRequest 物件的方式來寫的，因此當事實上回傳的已經是一個字串時，也就不會有 responseText 囉（因為回傳值本身就是responseText），然後 callback function 就理所當然的死掉了。</p>
<p>當我再把 1.0.1 版蓋回去測試時，卻發現程式跑起來一切正常，一丁點錯誤訊息也沒有；原來 1.0.1 版 success 的部份的確是回傳一個 XMLHttpRequest 物件，所以或許是在 1.0.2 版有作更改了吧，不過我怎樣也找不到哪邊有 change log 提到這點，也找不到舊版的 API 文件來作對照，但是經過一連串的交叉測試之後應該可以確定是這樣子沒錯。所以這下子有兩個選擇：一個是把 success 改成 complete，這樣就不用去更動 callback function，另一個是將 callback function 內的 XMLHttpRequestObject.responseText 改成直接用 responseText，亦即將</p>
<blockquote><p><code>function successCallBack(XMLHttpRequestObject){<br />
<span style="margin-left:40px;">eval("var jsonVars = " + XMLHttpRequestObject.responseText);</span><br />
<span style="margin-left:40px;">………</span><br />
}</code></p></blockquote>
<p>改成</p>
<blockquote><p><code>function successCallBack(responseText){<br />
<span style="margin-left:40px;">eval("var jsonVars = " + responseText);</span><br />
<span style="margin-left:40px;">………</span><br />
}</code></p></blockquote>
<p>而我選的是後者。</p>
<p>喔，其實還有另一個選擇，就是用舊版 library，但，何必咧？</p>
<p>真不知道為什麼要將 success 的部份設計的跟另外兩個狀態不一樣啊……</p>
<p><strong>2006-10-14 update :</strong><br />
<a href="http://jquery.com/blog/">jQuery 的官方部落格</a>今天<a href="http://jquery.com/blog/2006/10/13/minor-api-change-in-102/">提到了這點</a>：其實這項 API 的變動，原本是預計等到 1.1 版的 major release 時才會變更的，結果「不小心」在 1.0.2 時就先用了，然後又順便忘了提到這點……</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kej.tw/2006-10/12/jquery-102/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP設定錯誤回報等級</title>
		<link>http://blog.kej.tw/2005-10/09/php_error_reporting/</link>
		<comments>http://blog.kej.tw/2005-10/09/php_error_reporting/#comments</comments>
		<pubDate>Sun, 09 Oct 2005 11:46:51 +0000</pubDate>
		<dc:creator><![CDATA[Kej]]></dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.kejjang.com/?p=4</guid>
		<description><![CDATA[用error_reporting()函式來自訂錯誤回報的等級，以取得所有的錯誤/警告/注意信息]]></description>
				<content:encoded><![CDATA[<p>開始寫PHP以來，就對一個小地方很感冒，就是PHP並沒有禁止使用未宣告或初始化過的變數，也沒有提出警告。大概是因為自己也算是個容易粗心大意的人吧，所以有時候會不小心將變數名稱key錯了或怎麼的，整個程式便跑出了奇怪、非預期的結果。這時要debug是非常吃力的一件事情，不禁讓我懷念起perl的use strict。</p>
<p>不過後來發現，這其實是PHP預設將注意信息(NOTICE)隱藏起來而已，因為會引起這些注意信息的錯誤(例如某變數未初始化)，並不會導致致命的結果，所以我們可以用error_reporting()函式來自訂錯誤回報的等級。</p>
<p>一般PHP預設值是7或2039，也就是<strong>E_ALL &#038; ~E_NOTICE</strong>(php.ini的寫法) 或 <strong>E_ALL ^ E_NOTICE</strong>(error_reporting函式內參數的寫法，我沒試過能不能混用，我懶嘛)。因此若是在程式內設定<strong>error_reporting(E_ALL)</strong>，便可以取得所有的錯誤 /警告 /注意信息，對於神經比較大條的程式設計師來說，debug就方便多了。當然程式完成之後，你也可以用<strong>error_reporting(0)</strong>來抑制所有錯誤警告，畢竟這些訊息是不需要給使用者看到的吧(呃，當然，如果你確定程式百分之百不會出錯的話)。</p>
<p>p.s.</p>
<ol style='margin-top:-10px'>
<li>在參數的使用上，應該儘可能使用E_ALL、E_WARNING等常數，盡量不要使用數字，以避免新版本的數字跟常數的定義規則發生變化。</li>
<li>當然，使用ini_set(&#8216;error_reporting&#8217;,E_ALL) 也能達到與error_reporting(E_ALL) 一樣的效果，不過為什麼要自找麻煩呢？ <img src="http://blog.kej.tw/wp-includes/images/smilies/icon_razz.gif" alt=":P" class="wp-smiley" />  </li>
</ol>
<p>參考：<a href="http://tw2.php.net/manual/tw/function.error-reporting.php">error_reporting()</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kej.tw/2005-10/09/php_error_reporting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
