views:

110

answers:

2

hi_all()

I have a problem with parsing http response.. I try send some values to client

>>>>return HttpResponse(first=True,second=True)

when parsing:

$.post('get_values',"",function(data){
                alert(data['first']); //The alert isn't shown!!!
            });

what is the right way to extract values from httpresponse

maybe I make a mistake when create my response..

+1  A: 

If you made your HttpResponse json:

return HttpResponse("{\"first\":true,
\"second\":false}")

then you could receive it as json

$.post('get_values',"",function(data){
                alert(data['first']); //The alert isn't shown!!!
            },"json");
Adam
+4  A: 

If you are trying to use json, you could do something like this:

Django

data = json.dumps({"FIRST":True, "SECOND":False})
    return HttpResponse(data, mimetype="application/json")

and get it as:

jQuery

$.getJSON(url, [data], function(data){
                alert(data['first']);
            });

getJSON is a jquery shorthand function equivalent to the $.ajax function:

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback
});
vitorbal