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

📄 engine.js

📁 dwr3第一个学习例子
💻 JS
📖 第 1 页 / 共 5 页
字号:
        var request = dwr.engine.batch.constructRequest(batch, batch.httpMethod);        if (batch.httpMethod == "GET") {          batch.iframe.setAttribute("src", request.url);        }        else {          // TODO: On firefox we can now get the values of file fields, maybe we should use this          // See http://soakedandsoaped.com/articles/read/firefox-3-native-ajax-file-upload          // setting enctype via the DOM does not work in IE, create the form using innerHTML instead          var formHtml = "<form id='dwr-form' action='" + request.url + "' target='" + idname + "' style='display:none;' method='" + batch.httpMethod + "'";          if (batch.encType) formHtml += " enctype='" + batch.encType + "'";          formHtml += "></form>";          var div = batch.document.createElement("div");          div.innerHTML = formHtml;          batch.form = div.firstChild;          for (var prop in batch.map) {            var value = batch.map[prop];            if (typeof value != "function") {              if (value.tagName && value.tagName.toLowerCase() == "input" && value.type && value.type.toLowerCase() == "file") {                // Since we can not set the value of a file object, we must post the actual file object                // that the user clicked browse on. We will put a clone in it's place.                var clone = value.cloneNode(true);                value.removeAttribute("id", prop);                value.setAttribute("name", prop);                value.parentNode.insertBefore(clone, value);                value.parentNode.removeChild(value);                batch.form.appendChild(value);              } else {                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();        }      },      /**       * Called from iframe onload, check batch using batch-id       * @private       * @param {int} batchId The id of the batch that has loaded       */      loadingComplete:function(batchId) {        var batch = dwr.engine._batches[batchId];        if (batch) dwr.engine.batch.validate(batch);      },      /**       * Functions designed to be called by the server       */      remote:{        /**         * Called by the server: An IFrame reply is about to start         * @private         * @param {Object} iframe         * @param {int} batchId         */        beginIFrameResponse:function(iframe, batchId) {          if (iframe != null) dwr.engine._receivedBatch = iframe.batch;          dwr.engine._callPostHooks(dwr.engine._receivedBatch);        },        /**         * Called by the server: An IFrame reply is just completing         * @private         * @param {int} batchId         */        endIFrameResponse:function(batchId) {          dwr.engine.batch.remove(dwr.engine._receivedBatch);          dwr.engine._receivedBatch = null;        }      },      remove:function(batch) {        // TODO: make it so that we don't need these if statements        if (batch.div) {            batch.div.parentNode.removeChild(batch.div);        }        if (batch.iframe) {          batch.iframe.parentNode.removeChild(batch.iframe);        }        if (batch.form) {          batch.form.parentNode.removeChild(batch.form);        }      }      /*      // If we have an iframe comet solution where we need to read data streamed      // into an iframe then we need code like this to slurp the data out.      // Compare this with xhr.checkCometPoll()      outstandingIFrames:[],      checkCometPoll:function() {        for (var i = 0; i < dwr.engine.transport.iframe.outstandingIFrames.length; i++) {          var text = "";          var iframe = dwr.engine.transport.iframe.outstandingIFrames[i];          try {            text = dwr.engine.transport.iframe.getTextFromCometIFrame(iframe);          }          catch (ex) {            dwr.engine._handleWarning(iframe.batch, ex);          }          if (text != "") dwr.engine.transport.xhr.processCometResponse(text, iframe.batch);        }        if (dwr.engine.transport.iframe.outstandingIFrames.length > 0) {          setTimeout(dwr.engine.transport.iframe.checkCometPoll, dwr.engine._pollCometInterval);        }      }      // We probably also need to update dwr.engine.remote.beginIFrameResponse()      // to call checkCometPoll.      // Extract the whole (executed and all) text from the current iframe      getTextFromCometIFrame:function(frameEle) {        var body = frameEle.contentWindow.document.body;        if (body == null) return "";        var text = body.innerHTML;        // We need to prevent IE from stripping line feeds        if (text.indexOf("<PRE>") == 0 || text.indexOf("<pre>") == 0) {          text = text.substring(5, text.length - 7);        }        return text;      };      // And an addition to iframe.remove():      {        if (batch.iframe) {          // If this is a poll frame then stop comet polling          for (var i = 0; i < dwr.engine.transport.iframe.outstandingIFrames.length; i++) {            if (dwr.engine.transport.iframe.outstandingIFrames[i] == batch.iframe) {              dwr.engine.transport.iframe.outstandingIFrames.splice(i, 1);            }          }        }      }      */    },    /**     * Functions for remoting through Script Tags     */    scriptTag:{      /**       * Setup a batch for transfer through a script tag       * @param {Object} batch The batch to alter for script tag transmit       */      send:function(batch) {        batch.mode = batch.isPoll ? dwr.engine._ModePlainPoll : dwr.engine._ModePlainCall;        var request = dwr.engine.batch.constructRequest(batch, "GET");        // The best option is DOM manipulation, but this only works after onload        // has completed        if (document.body) {          batch.script = document.createElement("script");          batch.script.id = "dwr-st-" + batch.map.batchId;          batch.script.src = request.url;          batch.script.type = "text/javascript";          document.body.appendChild(batch.script);        }        else {          document.writeln("<scr" + "ipt type='text/javascript' id='dwr-st-" + batch.map["c0-id"] + "' src='" + request.url + "'> </scr" + "ipt>");        }      }    },    /**     * Remoting through IE's htmlfile ActiveX control     */    htmlfile:{      /**       * Setup a batch for transfer through htmlfile       * @param {Object} batch The batch to alter for htmlfile transmit       */      send:function(batch) {        var idname = dwr.engine.transport.iframe.getId(batch);        batch.htmlfile = new window.ActiveXObject("htmlfile");        batch.htmlfile.open();        batch.htmlfile.write("<" + "html>");        batch.htmlfile.write("<div><iframe className='wibble' src='javascript:void(0)' id='" + idname + "' name='" + idname + "' onload='dwr.engine.transport.iframe.loadingComplete(" + batch.map.batchId + ");'></iframe></div>");        batch.htmlfile.write("</" + "html>");        batch.htmlfile.close();        batch.htmlfile.parentWindow.dwr = dwr;        batch.document = batch.htmlfile;        dwr.engine.transport.iframe.beginLoader(batch, idname);      }    }  };  /**   * Functions to manipulate batches   * @private   */  dwr.engine.batch = {    /**     * Generate a new standard batch     * @private     */    create:function() {      var batch = {        async:dwr.engine._async,        charsProcessed:0,        handlers:[],        isPoll:false,        map:{ callCount:0, windowName:window.name },        paramCount:0,        preHooks:[],        postHooks:[],        timeout:dwr.engine._timeout,        errorHandler:dwr.engine._errorHandler,        warningHandler:dwr.engine._warningHandler,        textHtmlHandler:dwr.engine._textHtmlHandler      };      if (dwr.engine._preHook) {        batch.preHooks.push(dwr.engine._preHook);      }      if (dwr.engine._postHook) {        batch.postHooks.push(dwr.engine._postHook);      }      dwr.engine.batch.populateHeadersAndParameters(batch);      return batch;    },    /**     * Generate a new batch for polling     * @private     * @see dwr.engine.batch.create()     */    createPoll:function() {      var batch = {        async:true,        charsProcessed:0,        handlers:[{          callback:function(pause) {            dwr.engine._pollRetries = 0;            setTimeout(dwr.engine._poll, pause);          }        }],        isPoll:true,        map:{ windowName:window.name },        paramCount:0,        path:dwr.engine._pathToDwrServlet,        preHooks:[],        postHooks:[],        timeout:0,        windowName:window.name,        errorHandler:dwr.engine._pollErrorHandler,        warningHandler:dwr.engine._pollErrorHandler,        textHtmlHandler:dwr.engine._textHtmlHandler      };      dwr.engine.batch.populateHeadersAndParameters(batch);      return batch;    },    /**     * Copy the global headers and parameters into this batch object     * @private     * @param {Object} batch The destination     */    populateHeadersAndParameters:function(batch) {      var propname, data;      batch.headers = {};      if (dwr.engine._headers) {        for (propname in dwr.engine._headers) {          data = dwr.engine._headers[propname];          if (typeof data != "function") batch.headers[propname] = data;        }      }      batch.parameters = {};      if (dwr.engine._parameters) {        for (propname in dwr.engine._parameters) {          data = dwr.engine._parameters[propname];          if (typeof data != "function") batch.parameters[propname] = data;        }      }    },    /**     * Augment this batch with a new call     * @private     */    addCall:function(batch, scriptName, methodName, args) {      // From the other params, work out which is the function (or object with      // call meta-data) and which is the call parameters      var callData, stopAt;      var lastArg = args[args.length - 1];      if (lastArg == null || typeof lastArg == "function") {        callData = { callback:lastArg };        stopAt = args.length - 1;      }      else if (typeof lastArg == "object" && (typeof lastArg.callback == "function"        || typeof lastArg.exceptionHandler == "function" || typeof lastArg.callbackHandler == "function"        || typeof lastArg.errorHandler == "function" || typeof lastArg.warningHandler == "function" )) {        callData = lastArg;        stopAt = args.length - 1;      }      else {        callData = {};        stopAt = args.length;      }      // Merge from the callData into the batch      dwr.engine.batch.merge(batch, callData);      batch.handlers[batch.map.callCount] = {        exceptionHandler:callData.exceptionHandler,        exceptionArg:callData.exceptionArg || callData.arg || null,        exceptionScope:callData.exceptionScope || callData.scope || window,        callback:callData.callbackHandler || callData.callback,        callbackArg:callData.callbackArg || callData.arg || null,              callbackScope:callData.callbackScope || callData.scope || window                };      // Copy to the map the things that need serializing      var prefix = "c" + batch.map.callCount + "-";      batch.map[prefix + "scriptName"] = scriptName;      batch.map[prefix + "methodName"] = methodName;      batch.map[prefix + "id"] = batch.map.callCount;      var converted = [];      for (var i = 0; i < stopAt; i++) {        dwr.engine.serialize.convert(batch, converted, args[i], prefix + "param" + i, 0);      }    },    /**     * Take further options and merge them into a batch     * @private     * @param {Object} batch The batch that we are altering     * @param {Object} overrides The object containing properties to copy into batch     */    merge:function(batch, overrides) {      var propname, data;      for (var i = 0; i < dwr.engine._propnames.length; i++) {        propname = dwr.engine._propnames[i];        if (overrides[propname] != null) batch[propname] = overrides[propname];      }      if (overrides.preHook != null) batch.preHooks.unshift(overrides.preHook);      if (overrides.postHook != null) batch.postHooks.push(overrides.postHook);      if (overrides.headers) {        for (propname in overrides.headers) {          data = overrides.headers[propname];          if (typeof data != "function") batch.headers[propname] = data;        }      }      if (overrides.parameters) {        for (propname in overrides.parameters) {          data = overrides.parameters[propname];          if (typeof data != "function") batch.map["p-" + propname] = "" + data;        }      }    },    /**     * Executed just before a transport sends the batch     * @private     * @param {Object} batch The batch to prepare for sending     */    prepareToSend:function(batch) {      batch.map.batchId = dwr.engine._nextBatchId;      dwr.engine._nextBatchId++;      dwr.engine._batches[batch.map.batchId] = batch;      dwr.engine._batchesLength++;      batch.completed = false;      // security details are 

⌨️ 快捷键说明

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