Hey everyone! After I do some operations, it there...
# ktor
h
Hey everyone! After I do some operations, it there a way to redirect a user to another page?
d
If you do the redirect before generating content (the preferred way):
call.respondRedirect("/path", permanent = false)
h
thanx
d
It is possible to do redirects also from html content, but not as recommended. Via html header:
Copy code
<meta http-equiv="refresh" content="0; url=/path" />
Or via javascript:
Copy code
<script type="text/javascript">
document.location.href = '/path';
</script>
h
Ah, okay.
Okay, related, but not really: Instead of redirecting the user, is there a way to update the html some how without reloading? Showing another text input, etc? I guess it’s possible with js/php, but how with ktor?
d
The same way as PHP: if you want to change the contents dynamically, you would have to use JS
You can use jquery for example
h
So no inbuilt library?
d
I don’t think that’s something related to ktor. Check examples from here: http://api.jquery.com/jquery.ajax/ You can generate a page in ktor and use jquery to read that page, extract a fragment of it and replace some content of your current page.
If you mean if ktor has a feature to generate that javascript. No, it doesn’t.
h
i was thinking of something like when you submit a form, it just updates the current page saying “thank you for submitting the form”, but you stay on the page, and it just shows a little input box, so you can fill it out again. but when you click it, it also runs some kotlin code, which i’ve already got working
d
that’s still javascript
javascript handling the onsubmit event of the form, preventing it from executing the default code
h
ah, ok
d
then you can in that code, add that text, and fetch another page without loading in your main frame
or creating an invisible iframe and setting the target of the frame there
but you would still need to use javascript to change the text
h
Ok. Thanks
👍 1