Nui Callbacks

So I’m trying to learn NUI functions. I have the client lua communicating to the js file. However, I can’t for some reason get the js to send callbacks to the lua.

This is what I have:

client.lua

RegisterNUICallback("destroy", function(data, cb)
		toChat('Callback Recieved!');

		cb('ok')
end)

listener.js

document.onkeyup = function(data)
        {
            if(data.which == 27) { //esc
                console.log('js key capture Worked!');
                $.post('http://myResource/destroy', JSON.stringify("exit"))
            }
        }

When I test this and hit escape I get the log message in the console saying ’js key capture Worked!' But I can’t get the callback to work. Also, the toChat() function works properly too, which just sends a message to the local client. So I’m not sure whats going on. Am I by chance writing the http:// post wrong?

The resource name has to be lowercase for NUI callbacks to work. Change myResource to myresource.

4 Likes

Thank you. Didn’t realize it was so picky!