ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. setBrowserAjaxHandler

Function

setBrowserAjaxHandler

ClientBrowserIdentical to MTA:SA

Answers page requests to a path from Lua, e.g. fetch("http://trilogy/local/api"). The function returns the response body and optionally a MIME type. With no function the handler is removed.

Syntax

bool setBrowserAjaxHandler(browser webBrowser, string url [, function handler = nil])

Arguments

webBrowserbrowser
A local browser.
urlstring
The path, e.g. "api/players".
handlerfunction, optional = nil
A function(get, post) returning the body and MIME type.

Returns

true on success.

Example

setBrowserAjaxHandler(browser, "api/gracze", function(get, post)
    local list = {}
    for _, p in ipairs(getElementsByType("player")) do
        list[#list + 1] = getPlayerName(p)
    end
    return toJSON(list), "application/json"
end)

Notes

It takes priority over a file. If a file exists at the same path, the page gets the Lua response.