Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery POST后处理响应对象_Jquery_Django - Fatal编程技术网

Jquery POST后处理响应对象

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 =

我正在使用django,并试图通过POST检索jQuery发送的列表

邮政编码:

$.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']);
    });

我不需要向处理程序发送任何数据,我只需要处理它在响应中返回的数据