template.html
<input type="text" id="text">
<input id="submit" name="submit" type="submit">
<div id="roro"></div>
<script type="text/javascript">
$('#submit').click(function(){
$.ajax({
url:'',
data : {'text':$('#submit').val()},
type: 'POST',
dataType : 'json',
success:function(data){
$('#roro').text(result['data']);
},
error:function(r){
alert(text);
}
});
});
</script>
view.py
@csrf_exempt
def construction(request):
if request.method == 'POST':
text = request.POST['text']
return render(request, 'pybo/construction_compare.html', text)
return render(request, 'pybo/construction_compare.html')
It’s a test for pass of variables.
So if it’s failed I want see variable on alert..
I found many of articles but I failed..
And It has many fault because I studying alone and My brain is not good 🙁
2
Answers
you have to specify the
url
in your ajax request.You should specify the url to the view function to the url in your script.