中央农村工作会议在北京召开_济南最新事件_湖南优化电商服务有限公司_建设网站不用考虑企业内部网的建设情况

网站技术的解决方案

移动网站建设是什么意思、网站大全免费的安卓系统、永久使用、不限域名、自己免费做一个网站

免费做起始页的网站?

中央农村工作会议在北京召开_济南最新事件_湖南优化电商服务有限公司_建设网站不用考虑企业内部网的建设情况

/***/ function(module, exports, __webpack_require__) {/* global window, document, location, Event, setTimeout *//*## MockXMLHttpRequest期望的功能:1. 完整地覆盖原生 XHR 的行为2. 完整地模拟原生 XHR 的行为3. 在发起请求时,自动检测是否需要拦截4. 如果不必拦截,则执行原生 XHR 的行为5. 如果需要拦截,则执行虚拟 XHR 的行为6. 兼容 XMLHttpRequest 和 ActiveXObjectnew window.XMLHttpRequest()new window.ActiveXObject("Microsoft.XMLHTTP")关键方法的逻辑:* new 此时尚无法确定是否需要拦截,所以创建原生 XHR 对象是必须的。* open 此时可以取到 URL,可以决定是否进行拦截。* send 此时已经确定了请求方式。规范:http://xhr.spec.whatwg.org/http://www.w3.org/TR/XMLHttpRequest2/参考实现:https://github.com/philikon/MockHttpRequest/blob/master/lib/mock.jshttps://github.com/trek/FakeXMLHttpRequest/blob/master/fake_xml_http_request.jshttps://github.com/ilinsky/xmlhttprequest/blob/master/XMLHttpRequest.jshttps://github.com/firebug/firebug-lite/blob/master/content/lite/xhr.jshttps://github.com/thx/RAP/blob/master/lab/rap.plugin.xinglie.js**需不需要全面重写 XMLHttpRequest?**http://xhr.spec.whatwg.org/#interface-xmlhttprequest关键属性 readyState、status、statusText、response、responseText、responseXML 是 readonly,所以,试图通过修改这些状态,来模拟响应是不可行的。因此,唯一的办法是模拟整个 XMLHttpRequest,就像 jQuery 对事件模型的封装。// Event handlersonloadstart loadstartonprogress progressonabort abortonerror erroronload loadontimeout timeoutonloadend loadendonreadystatechange readystatechange*/var Util = __webpack_require__(3)// 备份原生 XMLHttpRequestwindow._XMLHttpRequest = window.XMLHttpRequestwindow._ActiveXObject = window.ActiveXObject/*PhantomJSTypeError: '[object EventConstructor]' is not a constructor (evaluating 'new Event("readystatechange")')https://github.com/bluerail/twitter-bootstrap-rails-confirm/issues/18https://github.com/ariya/phantomjs/issues/11289*/try {new window.Event('custom')} catch (exception) {window.Event = function(type, bubbles, cancelable, detail) {var event = document.createEvent('CustomEvent') // MUST be 'CustomEvent'event.initCustomEvent(type, bubbles, cancelable, detail)return event}}var XHR_STATES = {// The object has been constructed.UNSENT: 0,// The open() method has been successfully invoked.OPENED: 1,// All redirects (if any) have been followed and all HTTP headers of the response have been received.HEADERS_RECEIVED: 2,// The response's body is being received.LOADING: 3,// The data transfer has been completed or something went wrong during the transfer (e.g. infinite redirects).DONE: 4}var XHR_EVENTS = 'readystatechange loadstart progress abort error load timeout loadend'.split(' ')var XHR_REQUEST_PROPERTIES = 'timeout withCredentials'.split(' ')var XHR_RESPONSE_PROPERTIES = 'readyState responseURL status statusText responseType response responseText responseXML'.split(' ')// https://github.com/trek/FakeXMLHttpRequest/blob/master/fake_xml_http_request.js#L32var HTTP_STATUS_CODES = {100: "Continue",101: "Switching Protocols",200: "OK",201: "Created",202: "Accepted",203: "Non-Authoritative Information",204: "No Content",205: "Reset Content",206: "Partial Content",300: "Multiple Choice",301: "Moved Permanently",302: "Found",303: "See Other",304: "Not Modified",305: "Use Proxy",307: "Temporary Redirect",400: "Bad Request",401: "Unauthorized",402: "Payment Required",403: "Forbidden",404: "Not Found",405: "Method Not Allowed",406: "Not Acceptable",407: "Proxy Authentication Required",408: "Request Timeout",409: "Conflict",410: "Gone",411: "Length Required",412: "Precondition Failed",413: "Request Entity Too Large",414: "Request-URI Too Long",415: "Unsupported Media Type",416: "Requested Range Not Satisfiable",417: "Expectation Failed",422: "Unprocessable Entity",500: "Internal Server Error",501: "Not Implemented",502: "Bad Gateway",503: "Service Unavailable",504: "Gateway Timeout",505: "HTTP Version Not Supported"}/*MockXMLHttpRequest*/function MockXMLHttpRequest() {// 初始化 custom 对象,用于存储自定义属性this.custom = {events: {},requestHeaders: {},responseHeaders: {}}}MockXMLHttpRequest._settings = {timeout: '10-100',/*timeout: 50,timeout: '10-100',*/}MockXMLHttpRequest.setup = function(settings) {Util.extend(MockXMLHttpRequest._settings, settings)return MockXMLHttpRequest._settings}Util.extend(MockXMLHttpRequest, XHR_STATES)Util.extend(MockXMLHttpRequest.prototype, XHR_STATES)// 标记当前对象为 MockXMLHttpRequestMockXMLHttpRequest.prototype.mock = true// 是否拦截 Ajax 请求MockXMLHttpRequest.prototype.match = false// 初始化 Request 相关的属性和方法Util.extend(MockXMLHttpRequest.prototype, {// https://xhr.spec.whatwg.org/#the-open()-method// Sets the request method, request URL, and synchronous flag.open: function(method, url, async, username, password) {var that = thisUtil.extend(this.custom, {method: method,url: url,async: typeof async === 'boolean' ? async : true,username: username,password: password,options: {url: url,type: method}})this.custom.timeout = function(timeout) {if (typeof timeout === 'number') return timeoutif (typeof timeout === 'string' && !~timeout.indexOf('-')) return parseInt(timeout, 10)if (typeof timeout === 'string' && ~timeout.indexOf('-')) {var tmp = timeout.split('-')var min = parseInt(tmp[0], 10)var max = parseInt(tmp[1], 10)return Math.round(Math.random() * (max - min)) + min}}(MockXMLHttpRequest._settings.timeout)// 查找与请求参数匹配的数据模板var item = find(this.custom.options)function handle(event) {// 同步属性 NativeXMLHttpRequest => MockXMLHttpRequestfor (var i = 0; i < XHR_RESPONSE_PROPERTIES.length; i++) {try {that[XHR_RESPONSE_PROPERTIES[i]] = xhr[XHR_RESPONSE_PROPERTIES[i]]} catch (e) {}}// 触发 MockXMLHttpRequest 上的同名事件that.dispatchEvent(new Event(event.type /*, false, false, that*/ ))}// 如果未找到匹配的数据模板,则采用原生 XHR 发送请求。if (!item) {// 创建原生 XHR 对象,调用原生 open(),监听所有原生事件var xhr = createNativeXMLHttpRequest()this.custom.xhr = xhr// 初始化所有事件,用于监听原生 XHR 对象的事件for (var i = 0; i < XHR_EVENTS.length; i++) {xhr.addEventListener(XHR_EVENTS[i], handle)}// xhr.open()if (username) xhr.open(method, url, async, username, password)else xhr.open(method, url, async)// 同步属性 MockXMLHttpRequest => NativeXMLHttpRequestfor (var j = 0; j < XHR_REQUEST_PROPERTIES.length; j++) {try {xhr[XHR_REQUEST_PROPERTIES[j]] = that[XHR_REQUEST_PROPERTIES[j]]} catch (e) {}}return}// 找到了匹配的数据模板,开始拦截 XHR 请求this.match = truethis.custom.template = itemthis.readyState = MockXMLHttpRequest.OPENEDthis.dispatchEvent(new Event('readystatechange' /*, false, false, this*/ ))},// https://xhr.spec.whatwg.org/#the-setrequestheader()-method// Combines a header in author request headers.setRequestHeader: function(name, value) {// 原生 XHRif (!this.match) {this.custom.xhr.setRequestHeader(name, value)return}// 拦截 XHRvar requestHeaders = this.custom.requestHeadersif (requestHeaders[name]) requestHeaders[name] += ',' + valueelse requestHeaders[name] = value},timeout: 0,withCredentials: false,upload: {},// https://xhr.spec.whatwg.org/#the-send()-method// Initiates the request.send: function send(data) {var that = thisthis.custom.options.body = data// 原生 XHRif (!this.match) {this.custom.xhr.send(data)return}// 拦截 XHR// X-Requested-With headerthis.setRequestHeader('X-Requested-With', 'MockXMLHttpRequest')// loadstart The fetch initiates.this.dispatchEvent(new Event('loadstart' /*, false, false, this*/ ))if (this.custom.async) setTimeout(done, this.custom.timeout) // 异步else done() // 同步function done() {that.readyState = MockXMLHttpRequest.HEADERS_RECEIVEDthat.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ ))that.readyState = MockXMLHttpRequest.LOADINGthat.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ ))that.status = 200that.statusText = HTTP_STATUS_CODES[200]// fix #92 #93 by @qddegtyathat.response = that.responseText = JSON.stringify(convert(that.custom.template, that.custom.options),null, 4)that.readyState = MockXMLHttpRequest.DONEthat.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ ))that.dispatchEvent(new Event('load' /*, false, false, that*/ ));that.dispatchEvent(new Event('loadend' /*, false, false, that*/ ));}},// https://xhr.spec.whatwg.org/#the-abort()-method// Cancels any network activity.abort: function abort() {// 原生 XHRif (!this.match) {this.custom.xhr.abort()return}// 拦截 XHRthis.readyState = MockXMLHttpRequest.UNSENTthis.dispatchEvent(new Event('abort', false, false, this))this.dispatchEvent(new Event('error', false, false, this))}})// 初始化 Response 相关的属性和方法Util.extend(MockXMLHttpRequest.prototype, {responseURL: '',status: MockXMLHttpRequest.UNSENT,statusText: '',// https://xhr.spec.whatwg.org/#the-getresponseheader()-methodgetResponseHeader: function(name) {// 原生 XHRif (!this.match) {return this.custom.xhr.getResponseHeader(name)}// 拦截 XHRreturn this.custom.responseHeaders[name.toLowerCase()]},// https://xhr.spec.whatwg.org/#the-getallresponseheaders()-method// http://www.utf8-chartable.de/getAllResponseHeaders: function() {// 原生 XHRif (!this.match) {return this.custom.xhr.getAllResponseHeaders()}// 拦截 XHRvar responseHeaders = this.custom.responseHeadersvar headers = ''for (var h in responseHeaders) {if (!responseHeaders.hasOwnProperty(h)) continueheaders += h + ': ' + responseHeaders[h] + '\r\n'}return headers},overrideMimeType: function( /*mime*/ ) {},responseType: '', // '', 'text', 'arraybuffer', 'blob', 'document', 'json'response: null,responseText: '',responseXML: null})// EventTargetUtil.extend(MockXMLHttpRequest.prototype, {addEventListener: function addEventListener(type, handle) {var events = this.custom.eventsif (!events[type]) events[type] = []events[type].push(handle)},removeEventListener: function removeEventListener(type, handle) {var handles = this.custom.events[type] || []for (var i = 0; i < handles.length; i++) {if (handles[i] === handle) {handles.splice(i--, 1)}}},dispatchEvent: function dispatchEvent(event) {var handles = this.custom.events[event.type] || []for (var i = 0; i < handles.length; i++) {handles[i].call(this, event)}var ontype = 'on' + event.typeif (this[ontype]) this[ontype](event)}})// Inspired by jQueryfunction createNativeXMLHttpRequest() {var isLocal = function() {var rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/var rurl = /^([\w.+-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/var ajaxLocation = location.hrefvar ajaxLocParts = rurl.exec(ajaxLocation.toLowerCase()) || []return rlocalProtocol.test(ajaxLocParts[1])}()return window.ActiveXObject ?(!isLocal && createStandardXHR() || createActiveXHR()) : createStandardXHR()function createStandardXHR() {try {return new window._XMLHttpRequest();} catch (e) {}}function createActiveXHR() {try {return new window._ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}// 查找与请求参数匹配的数据模板:URL,Typefunction find(options) {for (var sUrlType in MockXMLHttpRequest.Mock._mocked) {var item = MockXMLHttpRequest.Mock._mocked[sUrlType]if ((!item.rurl || match(item.rurl, options.url)) &&(!item.rtype || match(item.rtype, options.type.toLowerCase()))) {// console.log('[mock]', options.url, '>', item.rurl)return item}}function match(expected, actual) {if (Util.type(expected) === 'string') {return expected === actual}if (Util.type(expected) === 'regexp') {return expected.test(actual)}}}// 数据模板 => 响应数据function convert(item, options) {return Util.isFunction(item.template) ?item.template(options) : MockXMLHttpRequest.Mock.mock(item.template)}module.exports = MockXMLHttpRequest/***/ } 微信公众号代运营网站策划方案名字自动点击器软件装修公司电话佛山企业网站建设平台怎么做网站插件上证e互动平台互联网舆情监测公司嘉兴网站建设方案推广企业qq官网登录seo免费自学的网站做一个自己的网页网易云商城上海房产网站家装公司需要哪些资质网站设计师岗位要求个人简历免费网站模板下载简单手工制作三亚网红公路河北省最穷的三个县司北京网站制作公司北京朝阳区疫情风险等级中国十大品牌购买网网页制作与网站发布服务器搭建软件山西已经宣布封城的城市办公空间设计风格网站建设的地方雪花crm最新版本邢台疫情最新消息今天新增管理系统都有哪些

猜你喜欢

  • 友情链接:
  • html可视化设计器 免费销售网站 网站建设济南服务热线 网站建设费用一般多少钱 汕尾网络推广 公众号制作方法教程