holuzs Posted October 1, 2019 Share Posted October 1, 2019 I want to get text from a page with fetchRemote. So, when a player enter a command with a code, the fetchRemote call a site with 2 GET request. How can I get a simply text from the site? function newCommand(player, cmd, code) fetchRemote('http://domain.tld/index.php?get&code='..code, function(data, error) if (error) then return print(error); end end); end addCommandHandler('cmd', newCommand); Link to comment
Moderators Patrick Posted October 1, 2019 Moderators Share Posted October 1, 2019 (edited) If fetch was success, the 'error' equals 0. So, 'if (error) then' always true. You need to terminate the function and print the error, if 'error' not equals or greater then 0. Hungarian: A visszakapott error változó mindig vesz fel értéket, ha minden rendben volt, akkor nullát. Mivel 'if (error) then' mindig igaz lesz, ezért minden esetben kilépsz a funckcióból a returnal. Correct: -- SERVER SIDE function newCommand(player, cmd, code) fetchRemote('http://domain.tld/index.php?get&code='..code, function(data, error) if (error ~= 0) then return print(error); end print("Result: " .. data); end); end addCommandHandler('cmd', newCommand); Edited October 1, 2019 by stPatrick 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now