HTML元素动态
我制作了一个输入号字段,并希望动态渲染在容器中的值,而无需重新加载页面。我为此使用了Ajax,但我仍然必须重新加载页面。
HTML:
<form method="post">
<div class="main">
<label for="numb">Parcour</label><br><br>
<input type="number" id="numb" min="1">
</div>
<div class="main" style="display: block;">
<section id="erstellen">
</section>
</div>
</form>
JS:
const xhr = new XMLHttpRequest();
xhr.open("POST","dynamisch_ajax.html", true);
xhr.onload = () => {
if(xhr.status === 200)
{
$('#erstellen').html($('#numb').val())
} else {
alert('Irgendetwas past nicht')
}
}
xhr.send();
I made a input number field and want to dynamic render the value of this in the container without reloading the page. I'm using ajax for this but I still have to reload the page.
HTML:
<form method="post">
<div class="main">
<label for="numb">Parcour</label><br><br>
<input type="number" id="numb" min="1">
</div>
<div class="main" style="display: block;">
<section id="erstellen">
</section>
</div>
</form>
js:
const xhr = new XMLHttpRequest();
xhr.open("POST","dynamisch_ajax.html", true);
xhr.onload = () => {
if(xhr.status === 200)
{
$('#erstellen').html($('#numb').val())
} else {
alert('Irgendetwas past nicht')
}
}
xhr.send();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用预防违规方法来防止默认刷新:
you must use from preventDefault method to prevent default refresh :