Jquery POST后处理响应对象
我正在使用django,并试图通过POST检索jQuery发送的列表 邮政编码:Jquery POST后处理响应对象,jquery,django,Jquery,Django,我正在使用django,并试图通过POST检索jQuery发送的列表 邮政编码: $.ajax({ method: 'POST', url:'/coupons/sideContentCoupons/', success: function(data){ // access response and retrieve data. } }); 处理程序: def sideContentCoupons(request): response =
$.ajax({
method: 'POST',
url:'/coupons/sideContentCoupons/',
success: function(data){
// access response and retrieve data.
}
});
处理程序:
def sideContentCoupons(request):
response = HttpResponse("", None, 200, "")
response['field'] = "data"
return response
这是访问“字段”的基本尝试,但我无法获取“数据”
如何访问该字段?您无法获取数据,因为您没有发送任何数据 试试这个:
$.ajax({
type: 'POST',
data: //this can either be a query string eg. foo=bar&bar=foo or an object
// {foo:'bar', bar:'foo'}
url:'/coupons/sideContentCoupons/',
success: function(data){
// access response and retrieve data.
}
});
你对你想做什么的描述有点混乱,但是如果我理解正确的话,它是通过Ajax从Django发送到jQuery,并访问那里的数据,这是你要问的 如果是这样,您可能应该考虑将数据作为JSON发送
def handler(request):
return HttpResponse(simplejson.dumps({'field': 'data'}))
$.getJSON('/coupons/sideContentCoupons/',
function(data) {
alert(data['field']);
});
我不需要向处理程序发送任何数据,我只需要处理它在响应中返回的数据