Getting started with Kotlin using AJAX


#1

Hello to all, this is my first post in this forum.

I have java and android experiences but got interested in kotlin only a few days ago. I really don’t linke writing javascript code, so i was happy to see that there is a new language like kotlin, that can compile to javascript.

Anyway, i already understand the basic syntax of kotlin, but have problems getting deeper into it, because i don’t find many kotlin tutorials. Right now i just want to experiment with kotlin by writting a simple programm with a kotin/javascript client that can receive json from a kotlin server (hoping to be able to use the same dto in for the server and the client). But i already stuck at the beginning, because i don’t find any example how to send an AJAX request to the server.

Thanks in advance for any help.


#2
@native class XMLHttpRequest
fun main(args: Array<String>) {
 var xhttp :dynamic= XMLHttpRequest();
 xhttp.open("GET", "http://www.example.com/", true);
 xhttp.onreadystatechange=fun(){
        println(xhttp.readyState)
        println(xhttp.status)
        println(xhttp.responseText)
    }
 xhttp.send();
}

#3

You can find simple example here, but it using jquery for requests instead of pure XMLHttpRequest