Home Reference Source
public class | source

Communication

This class is responsible for server communication using http requests

Constructor Summary

Public Constructor
public

constructor(form: FormData)

Creates an instance of Communication

Member Summary

Public Members
public get

form: FormData: *

Returns the FormData object attached to the request.

Method Summary

Public Methods
public

cancel()

Abort a request

public

Clears all the set headers

public

Delete a header by key

public

get(url: String)

Initiate a GET request

public

Gets a header by key

public

Returns an object containing all the headers sets

public

listener(progress: Function, end: Function)

Sets a listener to track the progress of the request

public

parseUrl(url: String): *

Parse a url to the correct format

public

post(url: String)

Initiate a POST request

public

send(url: String, method: String)

Initiate the request

public

setHeader(name: String, value: String)

Sets a header to the request

Public Constructors

public constructor(form: FormData) source

Creates an instance of Communication

Params:

NameTypeAttributeDescription
form FormData
  • optional

An existing form that would be sent

Public Members

public get form: FormData: * source

Returns the FormData object attached to the request. This makes it easier to control the fields.

Return:

FormData

FormData attached to the request

Public Methods

public cancel() source

Abort a request

public clearHeaders() source

Clears all the set headers

public deleteHeader(name: String) source

Delete a header by key

Params:

NameTypeAttributeDescription
name String

Header name

public get(url: String) source

Initiate a GET request

Params:

NameTypeAttributeDescription
url String

The url to request to

public getHeader(name: String): String source

Gets a header by key

Params:

NameTypeAttributeDescription
name String

Header name

Return:

String

Header value

public getHeaders(): Object source

Returns an object containing all the headers sets

Return:

Object

Object containing all the headers

public listener(progress: Function, end: Function) source

Sets a listener to track the progress of the request

Params:

NameTypeAttributeDescription
progress Function
  • optional
  • default: null

This function has two parameters, one parameter represents the progress value and the second is the event for onprogress

end Function

This function has three parameters, one parameter is the error and one which contains the responseText, and the third one will contain the entire event of onloadend

public parseUrl(url: String): * source

Parse a url to the correct format

Params:

NameTypeAttributeDescription
url String

The url to request to

Return:

*

public post(url: String) source

Initiate a POST request

Params:

NameTypeAttributeDescription
url String

The url to request to

public send(url: String, method: String) source

Initiate the request

Params:

NameTypeAttributeDescription
url String

The url to request to

method String

Either POST or GET

public setHeader(name: String, value: String) source

Sets a header to the request

Params:

NameTypeAttributeDescription
name String

Header name

value String

Header value