Wednesday, August 27, 2014

response to ajax (jquery) with variables

Hello,

i hope you can help me with this, I'm trying to send to an ajax (jquery from my html template) a response but i would like to send also a new variable.

in my html template I have:

    $("#init_date").click(function(){
        var some_date = {'init_date': init_date, 'end_date': end_date};
        $.post("/filter_dates/", some_date, function(response){
            if(response === 'success'){
                MAKE SOMETHING!!!
            else{ alert('error'); }
        });
    });

my django view look like:

def filter_date(request):
    if request.method == 'POST':
        example = ['A','B','C']
        init_date = request.POST['init_date']
        end_date = request.POST['end_date']
         MAKE SOMETHING!!
        return HttpResponse('success') AND HERE I WOULD LIKE TO SEND THE example ARRAY...
    else:
        return HttpResponse('error')

How can I send the array o some other variable as response?

Regards,
AR

No comments:

Post a Comment