当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - 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. Now I want to display this output back in the same html page in one particular DIV.

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

<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.

Kindly let me know how to send the values from javascript to HTML DIV and display it.

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: