Reputation: 99
I am having a small django view that responds with an dict, on an ajax call . Here is the code below :
Ajax Call :
var getdata = function(e){
var id = this.id;
console.log(id);
$.ajax({
url:'/editcontact/',
method :'POST',
data :{
'name' : id,
},
success:function(){
console.log("success");
},
error:function(status){
console.log (status);
}
});
};
$("button").on('click',getdata);
views.py
if request.is_ajax:
print "comes here"
value1 = request.GET['name']
print value1
data = dbs.objects.filter(cname=value1)
print data
return render_to_response("editcontact.html",{"data":data}, context_instance=RequestContext(request))
the code is executing till print data, but the render_to_response is not working.
Upvotes: 0
Views: 358
Reputation: 9828
I will suggest you to return response in json format. that will solve your problem. you can take help from below given code and can change your views.py
import json if request.is_ajax: print "comes here" value1 = request.GET['name'] print value1 data = dbs.objects.filter(cname=value1) json = simplejson.dumps(data) return HttpResponse(json, mimetype='application/json')
Upvotes: 1