UNPKG

apex4x

Version:

The Comprehensive ARIA Development Suite

103 lines 8.12 kB
�� Function: Get(objectKeyValueMapOrArrayOfMaps) Description: Exicutes one or more consecutive Fetch API queries. Returns: Null. Note: When chained together within the same array, each fetch object will only exicute after the successful completion of the one before it. However, when multiple Get() functions are exicuted in succession with separate objects, then processing is handled asynchronously to maximize performance. Configuration Properties { url: "resourcePath", data: { // Options: "html", "text", "xml", "json" returnType: "html", // Sets a CSS query selector to return the first matching node within the newly loaded html or xml. selector: "", // Fetch API method: "GET", headers: {}, // request headers. format is the identical to that accepted by the Headers constructor body: null, // request body. can be null, a string, a Buffer, a Blob, or a Node.js Readable stream cache: "default", // The cache mode you want to use for the request: default, no-store, reload, no-cache, force-cache, or only-if-cached. redirect: "follow", // The redirect mode to use: follow (automatically follow redirects), error (abort with an error if a redirect occurs), or manual (handle redirects manually). In Chrome the default is follow (before Chrome 47 it defaulted to manual). keepalive: false, // The keepalive option can be used to allow the request to outlive the page. Fetch with the keepalive flag is a replacement for the Navigator.sendBeacon() API. mode: 'cors', // The mode you want to use for the request, e.g., cors, no-cors, or same-origin. credentials: 'omit', // The request credentials you want to use for the request: omit, same-origin, or include. To automatically send cookies for the current domain, this option must be provided. Starting with Chrome 50, this property also takes a FederatedCredential instance or a PasswordCredential instance. referrer: 'client', // A USVString specifying no-referrer, client, or a URL. The default is client. referrerPolicy: 'no-referrer', // Specifies the value of the referer HTTP header. May be one of no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, unsafe-url. signal: null, // An AbortSignal object instance; allows you to communicate with a fetch request and abort it if desired via an AbortController. integrity: null // Contains the subresource integrity value of the request (e.g., sha256-BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=). }, success: function(content, promise){ }, error: function(error, promise){ } } Example: // Fetch an HTML page from an external resource using basic settings. $A.Get({ url: "/src/content.html", success: function(content, promise){ // Do something with 'content' } }); // Fetch consecutive DOM elements from external resources that require synchronous processing. $A.Get([ // First, load resource1 { url: "/src/content1.html", data: { selector: "#widget" // Get the element with id="widget" }, success: function(content, promise){ // Do something with content } }, // Next, load resource2 { url: "/src/content2.html", data: { selector: "#options" // Get the element with id="options" }, success: function(content, promise){ // Do something with content } } // Continue... ]); // Fetch consecutive DOM elements from external resources using asynchronous processing. $A.Get( // First, load resource1 { url: "/src/content1.html", data: { selector: "#widget" // Get the element with id="widget" }, success: function(content, promise){ // Do something with content } } ); $A.Get( // Load resource2 { url: "/src/content2.html", data: { selector: "#options" // Get the element with id="options" }, success: function(content, promise){ // Do something with content } } );