본문 바로가기

web/Django

django ajax post data and view.py



ajax (javascirpt)


var SendInfo= [];

var data = {

    date:$("#datetimepicker").val(),

    time:$("#time").val(),

    people:$("#people").val()

}

SendInfo.push(data);


$.ajax({

    url: YOUR_URL,

    dataType: "json",

    data: JSON.stringify(SendInfo),

    type: 'POST',

    success: function(data){

        console.log(data.data)


    }

});



view.py


data = json.loads(request.body)

print data[0]["date"]

print data[0]["time"]

print data[0]["people"]