1

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 %}
Jisson
  • 3,566
  • 8
  • 38
  • 71

1 Answers1

0

try it this way

from django.utils import simplejson

data = []
data.append({"msg": 'Hi this message'})
json = simplejson.dumps(data)
return HttpResponse(json, mimetype='application/json')
Ahsan
  • 11,516
  • 12
  • 52
  • 79
  • The problem is I got a large json from server,Hence its difficult to parse it in view and add to dictionary with a key manualy – Jisson Oct 13 '11 at 08:09