registerNuiCallback
Client
Registers a function the calling resource's interface page calls with a fetch to /name on its own address.
bool registerNuiCallback(string name, function handler)
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The callback's name, the path the page requests without the /. |
| handler | function | Function called with (data, cb): data is the request's body read as JSON (an empty table if it is empty or invalid) and cb(response) answers the page with the table as JSON. |
Returns
true if it was registered. false if the resource shows no page (logs a warning).
It only works if the resource declares a page with <ui src="..."> in its meta.xml. Registering the same name again replaces the function.
Example
registerNuiCallback("buy", function(data, cb)
triggerServerEvent("shop:buy", localPlayer, data.item)
cb({ ok = true })
end)
-- in the page: fetch("/buy", { method: "POST", body: JSON.stringify({ item: "pizza" }) })NoteIf
cb is not called within 30 seconds, the page gets {}.