Jump to content

Get text from site with fetchRemote


holuzs

Recommended Posts

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

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 by stPatrick
  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...