I am doing ajax using jquery in django1.3,well its works fine. Am using jquery load method to fill a in a template.
I get a json object asychrosily when user cliks in a button.I pass it to another template(which i loading inside the div of first template ) as a dictionary. But am unaware of how I display it in template.(I tried to pasres json in template page),but its leads to error. Can any one suggest How can solve the problem?
So I used normal way parse json in view and pass it to template by using the method locals() in render_to_response(). Is it a good approch?
testjqyery.html
$(document).ready(function() {
$('#save').click(function(e)
{
e.preventDefault();
$( '#results' ).html( ' ' ).load( '{% url t %}' );
});
<div id="results"></div>
views.py
def testupdater(request):
// getting json from server
//contents_json = json.loads(...)
json_data = {'json_dict': contents_json}
return render_to_response( 'results.html' ,json_data,context_instance=RequestContext(request))
results.html
{% if json_dict|length %}
{% else %}
{% endif %}