Bitsmist Frameworks
Docs » AjaxUtil

AjaxUtil

Overview

AjaxUtil is a utility class that uses XMLHttpRequest to send an ajax request to a server.

Methods

ajaxRequest(options)

Type:XMLHttpRequest Asynchronous Static

Sends an ajax request to a server.

Parameters

ParameterTypeDescription
optionsObjectAjax options. Valid keys are:
“url”StringA URL to access.
“method”StringAn HTTP medhod. Ex. GET, POST, PUT
“data”ObjectData to send with the request.
“headers”ObjectAn object that contains headers to send with the request. Each item is passed to XMLHttpRequest.setRequestHeader().
“options”ObjectAjax options. Passed to XMLHttpRequest.

Return Value

XHR Object.

Examples

GET
let url = "https://api.example.com/members/1/"
let method = "GET";
 
BITSMIST.v1.AjaxUtil.ajaxRequest({url:url, method:method}).then((xhr) => {
    console.log(xhr.responseText);
});
POST
let url = "https://api.example.com/members/"
let method = "POST";
let item =  {"id":2, "name":"John"};
let headers = {
    "Content-Type":"application/json",
    "X-From": "www.example.com"
};
let options = {"withCredentials":true};
 
BITSMIST.v1.AjaxUtil.ajaxRequest({
    url:url, 
    method:method, 
    data:item, 
    headers:headers, 
    options:options
}).then((xhr) => {
    console.log(xhr.responseText);
});

loadScript(url)

Type:undefined Asynchronous Static

Loads a script file from the server and append it to the current page.

Parameters

ParameterTypeDescription
urlStringThe URL of the file.

Return Value

undefined

Previous Next

© 2019-2023 Masaki Yasutake

Bitsmist Frameworks

Table of Contents

Table of Contents

  • AjaxUtil
    • Overview
    • Methods
      • ajaxRequest(options)
      • loadScript(url)

GENERAL

  • Overview
  • Installation
  • Create a sample component

COMPONENT

  • Loading
  • Settings
  • Events
  • Extending with organizers

REFERENCE - COMPONENT

  • Component

REFERENCE - ORGANIZER

  • EventOrganizer
  • LoaderOrganizer
  • OrganizerOrganizer
  • SettingOrganizer
  • StateOrganizer
  • TemplateOrganizer

REFERENCE - STORE

  • Store
  • ChainableStore

REFERENCE - UTILITY

  • AjaxUtil
  • ClassUtil
  • Util