Wednesday, February 29, 2012

Jquery/ajax + django

Hello,

I've gotten this json object back from django.

I was wondering how do we use ajax/jquery to retrieve just the words that are highlighted?

I'm stumped.


{"new_list":{"blue": {"sub_datetime": "2012-02-29 22:14:44", "exp_datetime": "2012-03-07 22:14:44", "keyword": "blue"}, "teleport": {"sub_datetime": "2012-02-29 22:09:26", "exp_datetime": "2012-03-07 22:09:26", "keyword": "teleport"}, "blink182": {"sub_datetime": "2012-02-29 22:12:40", "exp_datetime": "2012-03-07 22:12:40", "keyword": "blink182"}, "a1": {"sub_datetime": "2012-02-29 22:13:31", "exp_datetime": "2012-03-07 22:13:31", "keyword": "a1"}, "jolie": {"sub_datetime": "2012-02-29 22:08:46", "exp_datetime": "2012-03-07 22:08:46", "keyword": "jolie"}, "santa claus": {"sub_datetime": "2012-02-29 22:14:13", "exp_datetime": "2012-03-07 22:14:13", "keyword": "santa claus"}}}


Here are the methods i've tried:

function updateKeywords(e) { e.preventDefault();
    var keyword_form = jQuery(e.target);
    alert("Yay Jquery is working!!!");
$.ajax({
url : keyword_form.attr('action'),
type : keyword_form.attr('method'),
data : keyword_form.serialize(),
dataType : 'json',
success : function(response) {alert("JSON Data: " + response.new_list.keyword);
},
});
}


});




Unfortunately, when i put the above, it returns an undefined json data.

When i just put response.new_list, it returns the whole chunk.

Do appreciate any help.



Best Regards,

Stanwin Siow



No comments:

Post a Comment