Function xAjax

  • ajax 简单封装

    Parameters

    • method: string

      Http Method

    • url: string

      地址/链接

    • Optionaloptions: {
          async?: boolean;
          contentType?: string;
          data?: any;
          fail?: any;
          params?: any;
          raw?: boolean;
          success?: any;
          withCredentials?: boolean;
      }

      请求配置

      • Optionalasync?: boolean
      • OptionalcontentType?: string
      • Optionaldata?: any
      • Optionalfail?: any
      • Optionalparams?: any
      • Optionalraw?: boolean
      • Optionalsuccess?: any
      • OptionalwithCredentials?: boolean

    Returns any

    xAjax('get', 'https://test.cn', { params: { test: 123, hello: 456 }, success: (data) => console.log('success', data), fail: (error) => console.log('fail', error) }); /// ajax
    xAjax('POST', 'https://test.cn', { contentType: 'application/json', data: { test: 123 }, success: (data) => console.log('success', data), fail: (error) => console.log('fail', error) }); /// ajax