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

📄 engine.js

📁 dwr3第一个学习例子
💻 JS
📖 第 1 页 / 共 5 页
字号:
/* * Copyright 2005 Joe Walker * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//** * The DWR object is also defined by dwr.util etc. */if (window['dojo']) dojo.provide('dwr.engine');if (typeof window['dwr'] == 'undefined') {  dwr = { };}(function() {  dwr.engine = { };  /**    * Set an alternative error handler from the default alert box.    * @param {Function} handler The function to call when an error happens    * @see http://getahead.org/dwr/browser/engine/errors    */  dwr.engine.setErrorHandler = function(handler) {    dwr.engine._errorHandler = handler;  };  /**    * Set an alternative warning handler from the default alert box.    * @param {Function} handler The function to call when a warning happens    * @see http://getahead.org/dwr/browser/engine/errors    */  dwr.engine.setWarningHandler = function(handler) {    dwr.engine._warningHandler = handler;  };  /**    * Setter for the text/html handler - what happens if a DWR request gets an HTML    * reply rather than the expected Javascript. Often due to login timeout    * @param {Function} handler The function to call on an unexpected text/html content type    */  dwr.engine.setTextHtmlHandler = function(handler) {    dwr.engine._textHtmlHandler = handler;  };  /**    * Set a default timeout value for all calls. 0 (the default) turns timeouts off.    * @param {Function} handler The function to call when we get bored of waiting for a call    * @see getahead.org/dwr/browser/engine/errors    */  dwr.engine.setTimeout = function(timeout) {    dwr.engine._timeout = timeout;  };  /**    * The Pre-Hook is called before any DWR remoting is done.    * @param {Function} handler The function to call before any remote calls    * @see getahead.org/dwr/browser/engine/hooks    */  dwr.engine.setPreHook = function(handler) {    dwr.engine._preHook = handler;  };  /**   * The Post-Hook is called after any DWR remoting is done.   * @param {Function} handler The function to call after any remote calls   * @see getahead.org/dwr/browser/engine/hooks   */  dwr.engine.setPostHook = function(handler) {    dwr.engine._postHook = handler;  };  /**   * Custom headers for all DWR calls   * @param {Object} headers Object containing name/value pairs for extra headers   * @see getahead.org/dwr/????   */  dwr.engine.setHeaders = function(headers) {    dwr.engine._headers = headers;  };  /**   * Custom parameters for all DWR calls   * @param {Object} parameters Object containing name/value pairs for extra request parameters   * @see getahead.org/dwr/????   */  dwr.engine.setParameters = function(parameters) {    dwr.engine._parameters = parameters;  };  /**   * Ensure that remote calls happen in the order in which they were sent? (Default: false)   * @param {boolean} ordered true to enable ordered processing   * @see getahead.org/dwr/browser/engine/ordering   */  dwr.engine.setOrdered = function(ordered) {    dwr.engine._ordered = ordered;  };  /**   * Do we ask the XHR object to be asynchronous? (Default: true)   * Warning: it is <strong>highly</strong> advised to use the default ofasync   * processing, especially when dealing with Internet based requests.   * @param {boolean} async false to enable sync processing for XHR queries   * @see getahead.org/dwr/browser/engine/options   */  dwr.engine.setAsync = function(async) {    dwr.engine._async = async;  };  /**   * Does the client actively check the server for updates? (Default: false)   * @param {boolean} async true to enable low latency reverse ajax   * @see getahead.org/dwr/browser/engine/options   */  dwr.engine.setActiveReverseAjax = function(activeReverseAjax) {    if (activeReverseAjax) {      // Bail if we are already started      if (dwr.engine._activeReverseAjax) return;      dwr.engine._activeReverseAjax = true;      dwr.engine._poll();    }    else {      // Can we cancel an existing request?      if (dwr.engine._activeReverseAjax && dwr.engine._pollReq) {        dwr.engine._pollReq.abort();      }      dwr.engine._activeReverseAjax = false;    }    // TODO: in iframe mode, if we start, stop, start then the second start may    // well kick off a second iframe while the first is still about to return    // we should cope with this but we don't  };  /**   * Turn server notification of page unload on and off   * @param {boolean} notify true or false depending on if we want to turn unload on or off   * @see getahead.org/dwr/browser/engine/options   */  dwr.engine.setNotifyServerOnPageUnload = function(notify) {    dwr.engine._isNotifyServerOnPageUnload = notify;  };  /**   * The default message handler.   * @param {String} message The text of the error message   * @param {Object} ex An error object containing at least a name and message   * @see getahead.org/dwr/browser/engine/errors   */  dwr.engine.defaultErrorHandler = function(message, ex) {    dwr.engine._debug("Error: " + ex.name + ", " + ex.message, true);    if (message == null || message == "") alert("A server error has occurred.");    // Ignore NS_ERROR_NOT_AVAILABLE if Mozilla is being narky    else if (message.indexOf("0x80040111") != -1) dwr.engine._debug(message);    else alert(message);  };  /**   * The default warning handler.   * @param {String} message The text of the error message   * @param {Object} ex An error object containing at least a name and message   * @see getahead.org/dwr/browser/engine/errors   */  dwr.engine.defaultWarningHandler = function(message, ex) {    dwr.engine._debug(message);  };  /**   * For reduced latency you can group several remote calls together using a batch.   * @see getahead.org/dwr/browser/engine/batch   */  dwr.engine.beginBatch = function() {    if (dwr.engine._batch) {      dwr.engine._handleError(null, { name:"dwr.engine.batchBegun", message:"Batch already begun" });      return;    }    dwr.engine._batch = dwr.engine.batch.create();  };  /**   * Finished grouping a set of remote calls together. Go and execute them all.   * @param {Object} options A options object to customize processing   * @see getahead.org/dwr/browser/engine/batch   */  dwr.engine.endBatch = function(options) {    var batch = dwr.engine._batch;    if (batch == null) {      dwr.engine._handleError(null, { name:"dwr.engine.batchNotBegun", message:"No batch in progress" });      return;    }    dwr.engine._batch = null;    if (batch.map.callCount == 0) {      return;    }    // The hooks need to be merged carefully to preserve ordering    if (options) {      dwr.engine.batch.merge(batch, options);    }    // In ordered mode, we don't send unless the list of sent items is empty    if (dwr.engine._ordered && dwr.engine._batchesLength != 0) {      dwr.engine._batchQueue[dwr.engine._batchQueue.length] = batch;    }    else {      return dwr.engine.transport.send(batch);    }  };  /**   * For use with file downloads. When a DWR function returns a binary download   * you can prompt the user to save it using this function   * @param {Object} data The binary data passed from DWR   */  dwr.engine.openInDownload = function(data) {    var div = document.createElement("div");    document.body.appendChild(div);    div.innerHTML = "<iframe width='0' height='0' scrolling='no' frameborder='0' src='" + data + "'></iframe>";  };  /**   * What is the current version DWR number   * DWR version numbers are of the form "Version 1.2.3.3128[.beta]", where:   * 1 is the major release number. Changes in major version number indicate   * significant enhancements in functionality   * 2 is the minor release number. Changes in minor version number indicate   * less significant changes in functionality   * 3 is the revision release number. Changes here typically indicate bug   * fixes only   * 3128 is the build number. This number increments for each build   * .beta is a release title that is generally only used for non production   * releases to indicate the purpose/quality of the release   * The label is these strings concatenated   */  dwr.version = {    /**     * Changes in major version number indicate significant enhancements     */    major:parseInt("${versionMajor}"),    /**     * Changes in minor version number indicate smaller enhancements     */    minor:parseInt("${versionMinor}"),    /**     * Changes with the revision number typically indicate bug-fixes only     */    revision:parseInt("${versionRevision}"),    /**     * The build number increments for each build     */    build:parseInt("${versionBuild}"),    /**     * Only used for non production releases to indicate the purpose/quality of     * the release. Example titles include 'milestone1' or 'beta3'.     */    title:"${versionTitle}",    /**     * The strings above concatenated     */    label:"${versionLabel}"  };  //==============================================================================  // Only private stuff below here  //==============================================================================  /** The session cookie name */  dwr.engine._sessionCookieName = "${sessionCookieName}"; // JSESSIONID  /** Is GET enabled for the benefit of Safari? */  dwr.engine._allowGetForSafariButMakeForgeryEasier = "${allowGetForSafariButMakeForgeryEasier}";  /** The script prefix to strip in the case of scriptTagProtection. */  dwr.engine._scriptTagProtection = "${scriptTagProtection}";  /** The default path to the DWR servlet */  dwr.engine._pathToDwrServlet = "${pathToDwrServlet}";  /** Do we use XHR for reverse ajax because we are not streaming? */  dwr.engine._pollWithXhr = "${pollWithXhr}";  /** These URLs can be configured from the server */  dwr.engine._ModePlainCall = "${plainCallHandlerUrl}";  dwr.engine._ModePlainPoll = "${plainPollHandlerUrl}";  dwr.engine._ModeHtmlCall = "${htmlCallHandlerUrl}";  dwr.engine._ModeHtmlPoll = "${htmlPollHandlerUrl}";  /** Do we make the calls async? Default to 'true' */  dwr.engine._async = Boolean("${defaultToAsync}");  /** The page id */  dwr.engine._scriptSessionId = null;  /** A function to be called before requests are marshalled. Can be null. */  dwr.engine._preHook = null;  /** A function to be called after replies are received. Can be null. */  dwr.engine._postHook = null;  /** A map of the batches that we have sent and are awaiting a reply on. */  dwr.engine._batches = {};  /** A count of the number of outstanding batches. Should be == to _batches.length unless prototype has messed things up */  dwr.engine._batchesLength = 0;  /** In ordered mode, the array of batches waiting to be sent */  dwr.engine._batchQueue = [];  /** Do we attempt to ensure that calls happen in the order in which they were  sent? This starts true until we have fetched the ids, when it is to false */  dwr.engine._ordered = true;  /** The current batch (if we are in batch mode) */  dwr.engine._batch = null;  /** The global timeout */  dwr.engine._timeout = 0;  /** Are we doing comet or polling? */  dwr.engine._activeReverseAjax = false;  /** The xhr object that we are using to poll */  dwr.engine._pollReq = null;  /** How many milliseconds between internal comet polls */  dwr.engine._pollCometInterval = 200;  /** How many times have we re-tried to poll? */  dwr.engine._pollRetries = 0;  dwr.engine._maxPollRetries = 10;  /** The intervals between successive retries in seconds */  dwr.engine._retryIntervals = [ 2, 5, 10, 60, 300 ];  /** Do we do a document.reload if we get a text/html reply? */  dwr.engine._textHtmlHandler = null;  /** If you wish to send custom headers with every request */  dwr.engine._headers = null;  /** If you wish to send extra custom request parameters with each request */  dwr.engine._parameters = null;  /** Batch ids allow us to know which batch the server is answering */  dwr.engine._nextBatchId = 0;  /** A list of the properties that need merging from calls to a batch */  dwr.engine._propnames = [ "async", "timeout", "errorHandler", "warningHandler", "textHtmlHandler" ];  /** Do we stream, or can be hacked to do so? */  dwr.engine._partialResponseNo = 0;  dwr.engine._partialResponseYes = 1;  dwr.engine._partialResponseFlush = 2;  /** Are we doing page unloading? */  dwr.engine._isNotifyServerOnPageUnload = false;  /**

⌨️ 快捷键说明

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