I want to pass the variable bt from Lua to JS to create a button but it’s not working. I get error in the console “cannot read property “hwButton” of undefined.”
Client:
RegisterNUICallback('NUITest', function(data)
SetNuiFocus(true, true)
local bt = "Hello World"
SendNUIMessage({
type = "myVar",
hwButton = bt
})
end)
HTML/JS:
<script>
$(function() {
window.addEventListener('message', function(event) {
if (event.data.type == "myVar"){
var btn = document.createElement("BUTTON");
var t = document.createTextNode(hwButton);
btn.appendChild(t);
document.body.appendChild(btn);
}
});
});
</script>
<button class="test"></button>
$(".test").click(function(){
$.post('http://test/ SOME FUNCTION', JSON.stringify({}));
});