[英]Send Output from javascript to html DIV in Django
I have an HTML page in Django where I send my input from the form to javascript and which will inturn will send it to the views, get processed and the output will come to javascript. 我在Django中有一个HTML页面,我将表单中的输入发送到javascript,然后将其发送到视图,进行处理,输出将转到javascript。 Now I want to display this output back in the same html page in one particular DIV.
现在我想在一个特定的DIV中的同一个html页面中显示此输出。
My form is 我的表格是
<form id="form_id" method="POST" action="/your_Value/">
{% csrf_token %}
<label for="your_Value">Sentence: </label>
<input id="your_Value" type="text" name="your_Value">
<input type="submit" value="Compare">
</form>
<div class="details"></div>
My javascript is 我的javascript是
<script type="text/javascript">
$(function() {
$(".details").hide();
$("#form_id").submit(function(event) {
event.preventDefault();
var friendForm = $(this);
var posting = $.post(friendForm.attr('action'), friendForm.serialize());
posting.done(function(data) {
$(".details").show();
});
posting.fail(function(data) {
alert("Fail")
});
});
});
</script>
Where the values from posting.done() should go to 'details' div. 来自posting.done()的值应该转到'details'div。
Kindly let me know how to send the values from javascript to HTML DIV and display it. 请告诉我如何将值从javascript发送到HTML DIV并显示它。
Thanks in advance!! 提前致谢!!
include a pointer for the output. 包括输出的指针。
posting.done(function(data) {
$(".details").show();
$(".details").html(data);
});
reference: https://www.w3schools.com/jquery/html_html.asp 参考: https : //www.w3schools.com/jquery/html_html.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.