So I am trying to create something very basic. It will be a server request to pull information from the database and pass that information to Javascript to be output via HTML. Now, I understand this is possible with NUI? I have read a lot and just need a very basic understanding/example of this to learn. I read a lot and haven’t found anything broken down with a working example, any feed back would be appreciated.
For example, I have a function that pulls a players information, money, bank, ect. I want to pass that information to JS so that I can output it into a GUI.
I’m on my phone so I’m unable to help you a lot. But a great example to see how that works is the default scoreboard resource.
Request a server event, trigger a client event on the source with the database information, use that data on the client event, and use it in SendNUIMesssage.
You will need to make a server event, client event, and a method to trigger the server event.
Jesus. I will attempt this, so should I assign variables to the client side then?
Thanks, and I will look at that, thank you.!
So I am looking at the scoreboard listener… and not sure if this is the best reference. So to be a bit more specific. Lets say I have a DIV to retrieve different columns from the database and insert them into specific ID’s into the HTML. For example,
So I have the gui all setup, it pops up i just need to retrieve the character information and output it.
div id = “money”>
/div>
div id = “bank”>/div>
This is my server side setup:
TriggerEvent(‘es:addCommand’, ‘charactersinfo’, function(source, args, user)
getCharacters(source, function(data)
TriggerClientEvent(‘esx_irpide:showCharacterInfo’, source, {})
end)
end)
end, {help = “View your characters information”})
RegisterNetEvent(‘esx_irpide:showCharacterInfo’)
AddEventHandler(‘esx_irpide:showCharacterInfo’, function()
if not isDead then
EnableGui(true)
end
end)
RegisterNUICallback(‘escape’, function(data, cb)
EnableGui(false)
end)
And I have nothing for JS lol…
For the JS i was thinking like…
document.getElementById(“id”).innerHTML = variablehere
And the variable would be received from client/server lua somehow?