kotlinjs build improvement
test post fetch for index
This commit is contained in:
parent
16939c7b6a
commit
af321c8aad
@ -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}"
|
||||
}
|
||||
|
||||
}
|
@ -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()
|
||||
}
|
||||
}
|
15
WebServer/src/js/Requester.kt
Normal file
15
WebServer/src/js/Requester.kt
Normal file
@ -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()
|
||||
}
|
||||
}
|
@ -24,18 +24,17 @@
|
||||
<!--Custom styles-->
|
||||
<link rel="stylesheet" type="text/css" href="css/index.css">
|
||||
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
|
||||
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
||||
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
|
||||
<link rel="icon" type="image/png" href="/favicon.png">
|
||||
|
||||
<script type="text/javascript" src="js/lib/kotlin.js"></script>
|
||||
<script type="text/javascript" src="js/WasteInformationServer.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript" src="js/lib/kotlin.js"></script>
|
||||
<script type="text/javascript" src="js/WasteInformationServer.js"></script>
|
||||
<div class="container">
|
||||
<div class="d-flex justify-content-center h-100">
|
||||
<div class="card">
|
||||
|
Loading…
Reference in New Issue
Block a user