So I created a function to fetch the body of a URL, but it doesn’t want to work.

Here’s the code:

function gethtmldata(url)
	returndata = "none"
	http.Fetch( url,
	function( body, len, headers, code )
		returndata = body
	function( ERR )
		returndata = ERR
	return returndata

I’ve googled around and can’t find anything, it always returns “none”(what I set it to return originally) but there are no errors. This is being run clientside.

You didn’t enter a URL if I’m correct. You need to enter a URL for it to send the request to. Such as:

[editline]12th September 2013[/editline]

Also, here’s the proper way to do it. Hopefully this helps I think I’m correct though.

local TheReturnedHTML = “”;

http.Fetch( “”,
function( body, len, headers, code )
TheReturnedHTML = body; – Get the body.
function( error )
– If not then do nothing. You can also have it print something to your console so you know if you’d like.

Use TheReturnedHTML to get your body. So like print(TheReturnedHTML) or something like that wherever you wanna use it.

In case you didn’t notice, it’s defined in the function, url. So when using the function you provide the URL. But even directly copying and pasting that (which is just a direct copy from the wiki) it doesn’t work. It’s as if it completely ignores HTTP.Fetch, and if I use HTTP.Get it doesn’t seem to know what it is at all and returns an error.

It’s because http.Fetch uses callbacks and returndata is being set after that function returned the data (which would be “none” since it isn’t changed at the time).

So should I set a timer before returning it?

Yeah, it’s from the wiki. Sorry forgot to mention that. That’s what I was going to say, I did this as well a couple weeks ago and it didn’t work either. Most of the HTML methods don’t work. I would have tried to give you the way I did it, but I can’t remember it and deleted it as it didn’t work. I tried the Wiki way and spent a while trying different ways on my own. None work.

For example (not related to your problem, I know): I tried to make a DLabel in derma that’ll show the URL of the current site. Sounds simple enough, but nothing worked. Even the old DHTMLControls doesn’t work.

The only thing I know that works for sure is OpenURL. I gave up on the other methods. Sorry if I wasn’t any help, I did my best. Seems to me like HTML is broken.