(Function) error - A function to be called if the request fails. The function gets passed two arguments: The XMLHttpRequest object and a string describing the type of error that occurred.
(Function) success - A function to be called if the request succeeds. The function gets passed one argument: The data returned from the server, formatted according to the ‘dataType’ parameter.
(Function) complete - A function to be called when the request finishes. The function gets passed two arguments: The XMLHttpRequest object and a string describing the type the success of the request.
而我的程式在 success 時的 callback function 卻也是以回傳一個 XMLHttpRequest 物件的方式來寫的,因此當事實上回傳的已經是一個字串時,也就不會有 responseText 囉(因為回傳值本身就是responseText),然後 callback function 就理所當然的死掉了。
當我再把 1.0.1 版蓋回去測試時,卻發現程式跑起來一切正常,一丁點錯誤訊息也沒有;原來 1.0.1 版 success 的部份的確是回傳一個 XMLHttpRequest 物件,所以或許是在 1.0.2 版有作更改了吧,不過我怎樣也找不到哪邊有 change log 提到這點,也找不到舊版的 API 文件來作對照,但是經過一連串的交叉測試之後應該可以確定是這樣子沒錯。所以這下子有兩個選擇:一個是把 success 改成 complete,這樣就不用去更動 callback function,另一個是將 callback function 內的 XMLHttpRequestObject.responseText 改成直接用 responseText,亦即將
function successCallBack(XMLHttpRequestObject){
eval(”var jsonVars = ” + XMLHttpRequestObject.responseText);
………
}
改成
function successCallBack(responseText){
eval(”var jsonVars = ” + responseText);
………
}