I have a script to open a nui menu by typing command “nui”, the project is called player-hud (the command is a test), but sending data back to server, for example to close the nui, it won’t work, receiving data works but sending not
client.lua:
RegisterNUICallback("main", function(data, cb)
print("TEST", "TEST")
chat(data.text, {0, 255, 0})
SetDisplay(false, false)
cb("OK")
end)
RegisterNUICallback("error", function(data, cb)
print("TEST")
chat(data.error, {255, 0, 0})
SetDisplay(false, false)
cb("OK")
end)
index.js:
$("#submit").click(function(event) {
let input_value = $("#input").val();
if (input_value.length >= 100) {
$.post(`http://player-hud/error`, JSON.stringify({
error: "Input was greater than 100"
}));
return
} else if (!input_value) {
$.post(`http://player-hud/error`, JSON.stringify({
error: "There was no input the field"
}));
return
}
console.log(input_value)
$.post(`http://player-hud/main`, JSON.stringify({
text: input_value
}));
});
PS: the data never came to the server the print("TEST")
got never printed
EDIT: Btw the html hides, even tho i dont hide the html in the javascript after posting, weird
I suggest actually creating a callback for what you are trying to send it to.
You only have “exit” as a callback but are trying to send it to “error” and “main”.
2 Likes
index.js
$("#submit").click(function(event) {
let input_value = $("#input").val();
if (input_value.length >= 100) {
$.post(`http://player-hud/error`, JSON.stringify({
error: "Input was greater than 100"
}), function(data) {
console.log(data)
});
return
} else if (!input_value) {
$.post(`http://player-hud/error`, JSON.stringify({
error: "There was no input the field"
}), function(data) {
console.log(data)
});
return
}
console.log(input_value)
$.post(`http://player-hud/main`, JSON.stringify({
text: input_value
}), function(data) {
console.log(data)
});
return
});
client.lua
RegisterNUICallback("main", function(data, cb)
print("TEST", "TEST")
chat(data.text, {0, 255, 0})
SetDisplay(false, false)
cb("OK")
end)
RegisterNUICallback("error", function(data, cb)
print("TEST")
chat(data.error, {255, 0, 0})
SetDisplay(false, false)
cb("OK")
end)
now i set callback but still not working
btw: that exit was mistake it is actually called main
system
Closed
May 12, 2021, 7:25am
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.