$(document).ready(function (){
var $title_list = $('#title_list');
var $title = $('#id_title');
var $text = $('#id_text');
function list(card){
$title_list.append("<li>Title :"+card.title+"<br>Text : "+card.text+"</li>");
}
$("button").on('click',function(){
var card = {
title:$title.val(),
text:$text.val(),
csrfmiddlewaretoken: '{{ csrf_token }}', };
$.ajax({
type:"POST",
url:"/get/",
data: card,
success:function(order){
if ($('#id_title').val()=="" || $('#id_text').val()==""){
alert("type something")}
else{
list(order)
}
},
});
});
$.ajax({
type:"GET",
url:"/get/",
dataType:"json",
success: function(item){
$.each(item,function(key,value){
list(value)
});
}
});
});
When click the save button, i want to show the value we have just input. but the result show up with undefined, example:
1.Title :980 Text : 8989089
2.Title :undefined Text : undefined
def saveform(request):
form=CardForm(request.POST or None)
return render(request,'form.html',{'form':form})
def savegetform(request):
form=CardForm(request.POST or None)
if request.method=="POST":
if form.is_valid():
form.save()
else:
form=CardForm()
card_get=Card.objects.filter().values('title','text')
return HttpResponse(json.dumps(list(card_get)),content_type = "application/json" )
i dont want the output from id value, i want the output directly from the database when i do POST
Aucun commentaire:
Enregistrer un commentaire