diff --git a/WebServer/build.gradle b/WebServer/build.gradle index 4c972e5..feb9f8d 100644 --- a/WebServer/build.gradle +++ b/WebServer/build.gradle @@ -24,13 +24,13 @@ sourceSets { } compileKotlin2Js { - kotlinOptions.outputFile = "${projectDir}/web/lib/WasteInformationServer.js" - kotlinOptions.moduleKind = "amd" + kotlinOptions.outputFile = "${projectDir}/build/web/WasteInformationServer.js" + kotlinOptions.moduleKind = "plain" kotlinOptions.sourceMap = true } compileTestKotlin2Js { - kotlinOptions.moduleKind = "amd" + kotlinOptions.moduleKind = "plain" kotlinOptions.sourceMap = true } @@ -91,11 +91,4 @@ build.doLast() { from new File("build/classes/test") into "${web_dir}/lib" } - - copy { - includeEmptyDirs = false - from new File("build/resources/test") - into "${web_dir}" - } - } \ No newline at end of file diff --git a/WebServer/src/js/Main.kt b/WebServer/src/js/Main.kt index d414184..a43d3e8 100644 --- a/WebServer/src/js/Main.kt +++ b/WebServer/src/js/Main.kt @@ -1,3 +1,33 @@ +import org.w3c.dom.HTMLInputElement +import org.w3c.fetch.RequestInit +import org.w3c.xhr.XMLHttpRequest +import kotlin.browser.document +import kotlin.browser.window + fun main() { - println("success execute main") + val callurl = window.document.URL + if(callurl.contains("sec.html")){ + document.write("Hello, in document 2!") + }else { + window.onload = { + println("loaded sucessfully") + document.getElementById("loginbtn")?.addEventListener("click",{ + it.preventDefault() + println("clicked!!!") + + val username = document.getElementById("userfield") as HTMLInputElement + val passfield = document.getElementById("passfield") as HTMLInputElement + println(username.value) + + console.log("fetch 'data.json' with 'post'") + window.fetch("/senddata/loginget", RequestInit(method = "POST", body = "username=${username.value}&password=${passfield.value}")).then { + it.text().then { println(it) } + } + }) + } + document.write("Hello, world!") + + val req = Requester() + req.request() + } } \ No newline at end of file diff --git a/WebServer/src/js/Requester.kt b/WebServer/src/js/Requester.kt new file mode 100644 index 0000000..0c66168 --- /dev/null +++ b/WebServer/src/js/Requester.kt @@ -0,0 +1,15 @@ +import org.w3c.xhr.XMLHttpRequest + +class Requester { + fun request(){ + val test = XMLHttpRequest() + + test.open("GET","https://api.ipify.org?format=json") + + test.onload = { + println(test.responseText) + } + + test.send() + } +} \ No newline at end of file diff --git a/src/resources/wwwroot/index.html b/src/resources/wwwroot/index.html index 98b204b..5b2fe3c 100644 --- a/src/resources/wwwroot/index.html +++ b/src/resources/wwwroot/index.html @@ -24,18 +24,17 @@ - - + + +
- -