⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 engine.js

📁 里面包含dwr于struts
💻 JS
📖 第 1 页 / 共 4 页
字号:
    try {      batch.req.open(batch.httpMethod, request.url, batch.async);      try {        for (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._stateChange(batch);    }    catch (ex) {      dwr.engine._handleError(batch, ex);    }  }  else if (batch.rpcType != dwr.engine.ScriptTag) {    var idname = batch.isPoll ? "dwr-if-poll-" + batch.map.batchId : "dwr-if-" + batch.map.batchId;    // Removed htmlfile implementation. Don't expect it to return before v3    batch.div = document.createElement("div");    // Add the div to the document first, otherwise IE 6 will ignore onload handler.    document.body.appendChild(batch.div);    batch.div.innerHTML = "<iframe src='javascript:void(0)' frameborder='0' style='width:0px;height:0px;border:0;' id='" + idname + "' name='" + idname + "' onload='dwr.engine._iframeLoadingComplete (" + batch.map.batchId + ");'></iframe>";    batch.document = document;    batch.iframe = batch.document.getElementById(idname);    batch.iframe.batch = batch;    batch.mode = batch.isPoll ? dwr.engine._ModeHtmlPoll : dwr.engine._ModeHtmlCall;    if (batch.isPoll) dwr.engine._outstandingIFrames.push(batch.iframe);    request = dwr.engine._constructRequest(batch);    if (batch.httpMethod == "GET") {      batch.iframe.setAttribute("src", request.url);    }    else {      batch.form = batch.document.createElement("form");      batch.form.setAttribute("id", "dwr-form");      batch.form.setAttribute("action", request.url);      batch.form.setAttribute("style", "display:none;");      batch.form.setAttribute("target", idname);      batch.form.target = idname;      batch.form.setAttribute("method", batch.httpMethod);      for (prop in batch.map) {        var value = batch.map[prop];        if (typeof value != "function") {          var formInput = batch.document.createElement("input");          formInput.setAttribute("type", "hidden");          formInput.setAttribute("name", prop);          formInput.setAttribute("value", value);          batch.form.appendChild(formInput);        }      }      batch.document.body.appendChild(batch.form);      batch.form.submit();    }  }  else {    batch.httpMethod = "GET"; // There's no such thing as ScriptTag using POST    batch.mode = batch.isPoll ? dwr.engine._ModePlainPoll : dwr.engine._ModePlainCall;    request = dwr.engine._constructRequest(batch);    batch.script = document.createElement("script");    batch.script.id = "dwr-st-" + batch.map["c0-id"];    batch.script.src = request.url;    document.body.appendChild(batch.script);  }};dwr.engine._ModePlainCall = "/call/plaincall/";dwr.engine._ModeHtmlCall = "/call/htmlcall/";dwr.engine._ModePlainPoll = "/call/plainpoll/";dwr.engine._ModeHtmlPoll = "/call/htmlpoll/";/** @private Work out what the URL should look like */dwr.engine._constructRequest = function(batch) {  // A quick string to help people that use web log analysers  var request = { url:batch.path + batch.mode, body:null };  if (batch.isPoll == true) {    request.url += "ReverseAjax.dwr";  }  else if (batch.map.callCount == 1) {    request.url += batch.map["c0-scriptName"] + "." + batch.map["c0-methodName"] + ".dwr";  }  else {    request.url += "Multiple." + batch.map.callCount + ".dwr";  }  // Play nice with url re-writing  var sessionMatch = location.href.match(/jsessionid=([^?]+)/);  if (sessionMatch != null) {    request.url += ";jsessionid=" + sessionMatch[1];  }  var prop;  if (batch.httpMethod == "GET") {    // Some browsers (Opera/Safari2) seem to fail to convert the callCount value    // to a string in the loop below so we do it manually here.    batch.map.callCount = "" + batch.map.callCount;    request.url += "?";    for (prop in batch.map) {      if (typeof batch.map[prop] != "function") {        request.url += encodeURIComponent(prop) + "=" + encodeURIComponent(batch.map[prop]) + "&";      }    }    request.url = request.url.substring(0, request.url.length - 1);  }  else {    // PERFORMANCE: for iframe mode this is thrown away.    request.body = "";    if (document.all && !window.opera) {      // Use array joining on IE (fastest)      var buf = [];      for (prop in batch.map) {        if (typeof batch.map[prop] != "function") {          buf.push(prop + "=" + batch.map[prop] + dwr.engine._postSeperator);        }      }      request.body = buf.join("");    }    else {      // Use string concat on other browsers (fastest)      for (prop in batch.map) {        if (typeof batch.map[prop] != "function") {          request.body += prop + "=" + batch.map[prop] + dwr.engine._postSeperator;        }      }    }    request.body = dwr.engine._contentRewriteHandler(request.body);  }  request.url = dwr.engine._urlRewriteHandler(request.url);  return request;};/** @private Called by XMLHttpRequest to indicate that something has happened */dwr.engine._stateChange = function(batch) {  var toEval;  if (batch.completed) {    dwr.engine._debug("Error: _stateChange() with batch.completed");    return;  }  var req = batch.req;  try {    if (req.readyState != 4) return;  }  catch (ex) {    dwr.engine._handleWarning(batch, ex);    // It's broken - clear up and forget this call    dwr.engine._clearUp(batch);    return;  }  if (dwr.engine._unloading) {    dwr.engine._debug("Ignoring reply from server as page is unloading.");    return;  }    try {    var reply = req.responseText;    reply = dwr.engine._replyRewriteHandler(reply);    var status = req.status; // causes Mozilla to except on page moves    if (reply == null || reply == "") {      dwr.engine._handleWarning(batch, { name:"dwr.engine.missingData", message:"No data received from server" });    }    else if (status != 200) {      dwr.engine._handleError(batch, { name:"dwr.engine.http." + status, message:req.statusText });    }    else {      var contentType = req.getResponseHeader("Content-Type");      if (!contentType.match(/^text\/plain/) && !contentType.match(/^text\/javascript/)) {        if (contentType.match(/^text\/html/) && typeof batch.textHtmlHandler == "function") {          batch.textHtmlHandler({ status:status, responseText:reply, contentType:contentType });        }        else {          dwr.engine._handleWarning(batch, { name:"dwr.engine.invalidMimeType", message:"Invalid content type: '" + contentType + "'" });        }      }      else {        // Comet replies might have already partially executed        if (batch.isPoll && batch.map.partialResponse == dwr.engine._partialResponseYes) {          dwr.engine._processCometResponse(reply, batch);        }        else {          if (reply.search("//#DWR") == -1) {            dwr.engine._handleWarning(batch, { name:"dwr.engine.invalidReply", message:"Invalid reply from server" });          }          else {            toEval = reply;          }        }      }    }  }  catch (ex) {    dwr.engine._handleWarning(batch, ex);  }  dwr.engine._callPostHooks(batch);  // Outside of the try/catch so errors propogate normally:  dwr.engine._receivedBatch = batch;  if (toEval != null) toEval = toEval.replace(dwr.engine._scriptTagProtection, "");  dwr.engine._eval(toEval);  dwr.engine._receivedBatch = null;  dwr.engine._validateBatch(batch);  if (!batch.completed) dwr.engine._clearUp(batch);};/** * @private This function is invoked when a batch reply is received. * It checks that there is a response for every call in the batch. Otherwise, * an error will be signaled (a call without a response indicates that the  * server failed to send complete batch response).  */dwr.engine._validateBatch = function(batch) {  // If some call left unreplied, report an error.  if (!batch.completed) {    for (var i = 0; i < batch.map.callCount; i++) {      if (batch.handlers[i] != null) {        dwr.engine._handleWarning(batch, { name:"dwr.engine.incompleteReply", message:"Incomplete reply from server" });        break;      }    }  }}/** @private Called from iframe onload, check batch using batch-id */dwr.engine._iframeLoadingComplete = function(batchId) {  // dwr.engine._checkCometPoll();  var batch = dwr.engine._batches[batchId];  if (batch) dwr.engine._validateBatch(batch);}/** @private Called by the server: Execute a callback */dwr.engine._remoteHandleCallback = function(batchId, callId, reply) {  var batch = dwr.engine._batches[batchId];  if (batch == null) {    dwr.engine._debug("Warning: batch == null in remoteHandleCallback for batchId=" + batchId, true);    return;  }  // Error handlers inside here indicate an error that is nothing to do  // with DWR so we handle them differently.  try {    var handlers = batch.handlers[callId];    batch.handlers[callId] = null;    if (!handlers) {      dwr.engine._debug("Warning: Missing handlers. callId=" + callId, true);    }    else if (typeof handlers.callback == "function") handlers.callback(reply);  }  catch (ex) {    dwr.engine._handleError(batch, ex);  }};/** @private Called by the server: Handle an exception for a call */dwr.engine._remoteHandleException = function(batchId, callId, ex) {  var batch = dwr.engine._batches[batchId];  if (batch == null) { dwr.engine._debug("Warning: null batch in remoteHandleException", true); return; }  var handlers = batch.handlers[callId];  batch.handlers[callId] = null;  if (handlers == null) { dwr.engine._debug("Warning: null handlers in remoteHandleException", true); return; }  if (ex.message == undefined) ex.message = "";  if (typeof handlers.exceptionHandler == "function") handlers.exceptionHandler(ex.message, ex);  else if (typeof batch.errorHandler == "function") batch.errorHandler(ex.message, ex);};/** @private Called by the server: The whole batch is broken */dwr.engine._remoteHandleBatchException = function(ex, batchId) {  var searchBatch = (dwr.engine._receivedBatch == null && batchId != null);  if (searchBatch) {    dwr.engine._receivedBatch = dwr.engine._batches[batchId];  }  if (ex.message == undefined) ex.message = "";  dwr.engine._handleError(dwr.engine._receivedBatch, ex);  if (searchBatch) {    dwr.engine._receivedBatch = null;    dwr.engine._clearUp(dwr.engine._batches[batchId]);  }};/** @private Called by the server: Reverse ajax should not be used */dwr.engine._remotePollCometDisabled = function(ex, batchId) {  dwr.engine.setActiveReverseAjax(false);  var searchBatch = (dwr.engine._receivedBatch == null && batchId != null);  if (searchBatch) {    dwr.engine._receivedBatch = dwr.engine._batches[batchId];  }  if (ex.message == undefined) ex.message = "";  dwr.engine._handleError(dwr.engine._receivedBatch, ex);  if (searchBatch) {    dwr.engine._receivedBatch = null;    dwr.engine._clearUp(dwr.engine._batches[batchId]);  }};/** @private Called by the server: An IFrame reply is about to start */dwr.engine._remoteBeginIFrameResponse = function(iframe, batchId) {  if (iframe != null) dwr.engine._receivedBatch = iframe.batch;  dwr.engine._callPostHooks(dwr.engine._receivedBatch);};/** @private Called by the server: An IFrame reply is just completing */dwr.engine._remoteEndIFrameResponse = function(batchId) {  dwr.engine._clearUp(dwr.engine._receivedBatch);  dwr.engine._receivedBatch = null;};/** @private This is a hack to make the context be this window */dwr.engine._eval = function(script) {  if (script == null) return null;  if (script == "") { dwr.engine._debug("Warning: blank script", true); return null; }  // dwr.engine._debug("Exec: [" + script + "]", true);  return eval(script);};/** @private Called as a result of a request timeout */dwr.engine._abortRequest = function(batch) {  if (batch && !batch.completed) {    dwr.engine._clearUp(batch);    if (batch.req) batch.req.abort();    dwr.engine._handleError(batch, { name:"dwr.engine.timeout", message:"Timeout" });  }};/** @private call all the post hooks for a batch */dwr.engine._callPostHooks = function(batch) {  if (batch.postHooks) {    for (var i = 0; i < batch.postHooks.length; i++) {      batch.postHooks[i]();    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -