/**//** * Remoting through XHR */ xhr:{ /**//** * The default HTTP method to use */ httpMethod:"POST", /**//** * The ActiveX objects to use when we want to do an XMLHttpRequest call. * TODO: We arrived at this by trial and error. Other toolkits use * different strings, maybe there is an officially correct version? */ XMLHTTP:["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], /**//** * Setup a batch for transfer through XHR * @param {Object} batch The batch to alter for XHR transmit */ send:function(batch) { if (batch.isPoll) { batch.map.partialResponse = dwr.engine._partialResponseYes; } // Do proxies or IE force us to use early closing mode? if (batch.isPoll && dwr.engine._pollWithXhr =="true") { batch.map.partialResponse = dwr.engine._partialResponseNo; } if (batch.isPoll && dwr.engine.isIE) { batch.map.partialResponse = dwr.engine._partialResponseNo; } //看这里 if (window.XMLHttpRequest) { batch.req =new XMLHttpRequest(); } elseif (window.ActiveXObject) { batch.req = dwr.engine.util.newActiveXObject(dwr.engine.transport.xhr.XMLHTTP); } //看这里 // Proceed using XMLHttpRequest if (batch.async) { batch.req.onreadystatechange =function() { if (typeof dwr != 'undefined') { dwr.engine.transport.xhr.stateChange(batch); } }; } // If we're polling, record this for monitoring if (batch.isPoll) { dwr.engine._pollReq = batch.req; // In IE XHR is an ActiveX control so you can't augment it like this if (!document.all) batch.req.batch = batch; } httpMethod = dwr.engine.transport.xhr.httpMethod; // Workaround for Safari 1.x POST bug var indexSafari = navigator.userAgent.indexOf("Safari/"); if (indexSafari >=0) { var version = navigator.userAgent.substring(indexSafari +7); if (parseInt(version, 10) <400) { if (dwr.engine._allowGetForSafariButMakeForgeryEasier =="true") { httpMethod ="GET"; } else{ dwr.engine._handleWarning(batch, { name: "dwr.engine.oldSafari", message: "Safari GET support disabled. See getahead.org/dwr/server/servlet and allowGetForSafariButMakeForgeryEasier." }); } } } batch.mode = batch.isPoll ? dwr.engine._ModePlainPoll : dwr.engine._ModePlainCall; var request = dwr.engine.batch.constructRequest(batch, httpMethod); try{ batch.req.open(httpMethod, request.url, batch.async);//看这里,发送设置 try{ for (var prop in batch.headers) { var value = batch.headers[prop]; if (typeof value =="string") { batch.req.setRequestHeader(prop, value); } } if (!batch.headers["Content-Type"]) { batch.req.setRequestHeader("Content-Type", "text/plain"); } } catch (ex) { dwr.engine._handleWarning(batch, ex); } batch.req.send(request.body);//看这里,执行发送 if (!batch.async) { dwr.engine.transport.xhr.stateChange(batch); } } catch (ex) { dwr.engine._handleError(batch, ex); } if (batch.isPoll && batch.map.partialResponse == dwr.engine._partialResponseYes) { dwr.engine.transport.xhr.checkCometPoll(); } // This is only of any use in sync mode to return the reply data return batch.reply; },