client
RegisterNUICallback
FiveM client native documentation with a Lua example.
Summary
Registers a Lua handler the NUI (JS) can call via fetch. The way the UI sends actions back to the game (button clicks, form submits).
Returns
void
Parameters
namestringThe callback name.handlerfunctionfunction(data, cb) — call cb(result) to respond.Example
RegisterNUICallback('buy', function(data, cb)
-- data.item, data.amount from the UI
cb({ ok = true })
end)
-- JS: fetch(`https://${GetParentResourceName()}/buy`, {method:'POST', body: JSON.stringify({item})})Common pitfalls
- Always call cb(...) or the fetch on the JS side hangs.
- Validate NUI data — treat it like any untrusted input, especially before server actions.
Related natives
Related guides
FiveM scripts done right
Optimized, dual-framework scripts for QBCore and ESX from Viper Development — escrow protected, delivered instantly to your Cfx portal.
Browse Scripts →