HTML5 XMLHttpRequest Wrapper

Monkey Forums/Monkey Code/HTML5 XMLHttpRequest Wrapper

bruZard(Posted 2011) [#1]
i've created a small XMLHttpRequest Wrapper. It works with Firefox, Chrome and IE. I have not tested other browsers yet.

Demo: http://sedm.de/monkey/nettest/
Module: http://sedm.de/monkey/nettest/jnet.zip

Sample:


Methodlist of the class "XMLHttpRequest":


have fun!


DruggedBunny(Posted 2011) [#2]
Nice, thanks.


bruZard(Posted 2011) [#3]
Changes:
the getter methods are now fields, like in the original XMLHttpRequest object.

Additions:
jNet now has a Flash-Target. Flash Example at : http://sedm.de/monkey/nettest/MonkeyGame.html


pinete(Posted 2011) [#4]
Thanks a lot bruZard! very useful :)
could you please explain a little more how it works, for newbies? :P
thanks again!


bruZard(Posted 2011) [#5]
jNet is abandoned, use utils instead: http://www.sedm.de/monkey/utils.zip

1. create a new Object from XMLHttpRequest
Local xhr:XMLHttpRequest = new XMLHttpRequest()

2. open a HTTP Connection to a URL
xhr.open("google.com", "GET") ' GET is default, you can also use "POST"

3. send the request
xhr.send()

3. wait for the answer
If xhr.responseText.Length() doAnythingWithTheAnswer()


on Android you must set the correct permission to access the internet! Remind that not all ISP's allows XMLHttpRequest. preferably you should use it on the same Domain to get Highscores, load Data (like Leveldata) etc.


pinete(Posted 2011) [#6]
thanks!! ;)


thoast(Posted 2011) [#7]
Nice thank you


Michael(Posted 2012) [#8]
Thanks for providing this, but JFYI I noticed a very slight issue.

The equal sign was missing below, and the compiler was complaining about missing identifier for the function. I'm using v53.
#if TARGET "html5"
	Function Include:Void(url:String) = "utils_include"
#EndIf

Do you mind to please check & update it?

Also I feel a bit silly, but though I comment out the above, and tried your original jnet code, I could never get a response in either case. All I could get was 'undefined' as a response. Do you have a suggestion? Thanks.


Michael(Posted 2012) [#9]
Thanks for providing this, but JFYI I noticed a very slight issue.

The equal sign was missing below, and the compiler was complaining about missing identifier for the function. I'm using v53.

#if TARGET "html5"
	Function Include:Void(url:String) = "utils_include"
#EndIf


Do you mind to please check & update it?

Also I feel a bit silly, but though I comment out the above, and tried your original jnet code, I could never get a response. All I could get was 'undefined'. Do you have a suggestion? Thanks.


Michael(Posted 2012) [#10]
Sorry about the double post - not sure how it happened. I updated my original post a couple of times to include code formatting, but it seems to have duplicated my post after that.


bruZard(Posted 2012) [#11]
i've not looked at the utils module for a long time. Will try to clean it up


nigelibrown(Posted 2016) [#12]
has anyone still got a copy of this module? I have some historic code that used it but now dont have the module!


CopperCircle(Posted 2016) [#13]
httprequest is part of Monkey now, the module is in the brl folder and there is an example in mak's bananas folder.


bruZard(Posted 2016) [#14]
the XMLHttpRequest module is part of the utils module. I dont know if it work: http://www.colorflow.de/monkey/downloads/utils.zip


diemar(Posted 2016) [#15]
Funny, I was desperately searching for something like this I guess... Thanks