Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/oak_nest/modules/uinv/deps.ts>Ajax

Refer to nestjs to realize some common functions for Deno
Go to Latest
class Ajax
Re-export
import { Ajax } from "https://deno.land/x/oak_nest@v2.0.0/modules/uinv/deps.ts";

Constructors

new
Ajax(logger?: Logger)

Properties

private
logger: Logger
caches: Map
interceptors: { request: Interceptors<RequestCallback>; response: Interceptors<ResponseCallback>; }

Methods

private
cache_ajax(cfg: AjaxConfig): AjaxResult

缓存请求,同一时间同一请求只会向后台发送一次

private
clearCacheByKey(uniqueKey: string, cacheTimeout?: number)
private
core_ajax(mergedConfig: AjaxConfig): AjaxResult
private
fetch_timeout(
fecthPromise: Promise<any>,
controller: AbortController | undefined,
config: AjaxConfig,
)

实现fetch的timeout 功能

private
handleBaseUrl(url: string, baseURL?: string)
private
handleGetUrl(
url: string,
data: AjaxGetData,
isEncodeUrl?: boolean,
)
private
handlePostData(data: any, isFile?: boolean)
private
mergeAbortConfig(config: AjaxConfig, signal?: AbortSignal): AbortController | undefined
private
mergeResponse(promise: Promise<any>)
private
request(config: AjaxConfig)

进行fetch请求

protected
getUniqueKey(config: AjaxConfig)
abort(controller?: AbortController)

取消接口请求

取消所有接口请求

ajax<T>(cfg: AjaxConfig): Promise<T>

ajax主方法,返回promise

ajaxAbortResult<T>(cfg: AjaxConfig): AbortResult<T>

调用ajax的同时,返回取消ajax请求的方法

all_ajax(cfg: AjaxConfig): AjaxResult

手动清除缓存

get<T>(
url: string,
data?: AjaxGetData,
options?: AjaxExConfig,
)
getAbortResult<T>(
url: string,
data?: AjaxGetData,
options?: AjaxExConfig,
)

调用ajax的get请求的同时,返回取消ajax请求的方法

isAbortError(err: Error)
post<T>(
url: string,
data: AjaxPostData,
options?: AjaxExConfig,
)
postAbortResult<T>(
url: string,
data: AjaxPostData,
options?: AjaxExConfig,
)

调用ajax的post请求同时,返回取消ajax请求的方法

Static Properties

defaults: AjaxExConfig