<div class="cnt">列表6:函数getReadyStateHandler()<div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; width: 98%; padding-top: 4px; background-color: #eeeeee; border: #cccccc 1px solid;">/**//* * Returns a function that waits for the specified XMLHttpRequest * to complete, then passes its XML response to the given handler function. * req - The XMLHttpRequest whose state is changing * responseXmlHandler - Function to pass the XML response to */ function getReadyStateHandler(req, responseXmlHandler) { // 返回一个监听XMLHttpRequest实例的匿名函数 return function () { // 如果请求的状态是“完成” if (req.readyState == 4) { // 检查是否成功接收了服务器响应 if (req.status == 200) { // 将载有响应信息的XML传递到处理函数 responseXmlHandler(req.responseXML); } else { // 有HTTP问题发生 alert("HTTP error: "+req.status); } } } }