Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

之后在资源文件加的对应目录下新建common.js,本例为libraries目录下新建common.js

在common.js文件中覆盖dorado的AjaxEngine对象的getInstance方法,如下:js文件中覆盖XMLHttpRequest对象的open方法,如下:

Code Block
javascript
if (dorado.util.AjaxEngine){
	dorado.util.AjaxEngine.prototype._getUserSendDataXMLHttpRequest.prototype.nativeOpen = doradoXMLHttpRequest.util.AjaxEngine.prototype._getSendDataopen;
	dorado.util.AjaxEngine.prototype._getSendData = function(options){         var datacustomizeOpen = this._getUserSendData(options);
        console.log(data);
function (method, url, async, user, password) {
      // returndo data;
    }
}

在自定义的beforePost事件中对上传的数据进行个性化定义就可以。其中arg参数的结构参考:

Image Removed

如下范例就是动态添加header的一个示例:

Code Block
javascript
if (dorado.util.AjaxEngine){
	dorado.util.AjaxEngine.prototype._getUserSendData = dorado.util.AjaxEngine.prototype._getSendData;
	dorado.util.AjaxEngine.prototype._getSendData = function(options){something
	  console.log("abc");
        var data = this._getUserSendData(options);
    nativeOpen(method, url, async, user, password);
	    consolethis.log(optionssetRequestHeader("authKey", "abc");
        if (!options.headers){
        	options.headers = {};
        }
        options.headers.key1="123";
        return data;
    }
}

};
XMLHttpRequest.prototype.open = customizeOpen;