python - Return data to ajax function data shown in below format -
using jsondump in python need send response ajaxpage
object format in python shell show in below image
how use java server object notation function send response
//view output data
[<userpost: userpost object>, <userpost: userpost object>]
//this django view
def load_scroll_posts(request): if request.method == 'post': post_id = request.post['post_id'] loaded_posts = userpost.objects.filter(id__gte = post_id) return httpresponse(json.dumps({'up':loaded_posts}))
//this ajax function
function load_remain_user_posts() { var post_id = $(".message_box:last").attr("id"); var csrftoken = getcookie('csrftoken'); $.post('/theweber.in/load_m',{ post_id ':post_id,' csrfmiddlewaretoken ':csrftoken}, function(data){ //console.log(data) var obj = json.parse(data); console.log(obj) }); }
in console nothing displaying
perhaps mean pass 2 variables parameters post? like:
function load_remain_user_posts() { var post_id = $(".message_box:last").attr("id"); var csrftoken = getcookie('csrftoken'); var parameters = { "post_id": post_id, "csrfmiddlewaretoken": csrftoken }; $.post('/theweber.in/load_m', parameters, function (data) { //console.log(data) var obj = json.parse(data); console.log(obj) }); }
Comments
Post a Comment