Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
Python 从AJAX调用获取字段数据时遇到问题_Python_Ajax_Django_Django Views - Fatal编程技术网

Python 从AJAX调用获取字段数据时遇到问题

Python 从AJAX调用获取字段数据时遇到问题,python,ajax,django,django-views,Python,Ajax,Django,Django Views,我想做的是,当从下拉列表中选择金融机构时,我想进行一个AJAX调用,将选择的FI与我的查询进行比较 当我尝试打印所选数据时,每次都会得到None 这是我到目前为止所拥有的 edit.html javascript: q = $("#investment_form").serialize(); function cdic_limit() { $.ajax({ type: "POST", url: "{% url investments-calc_c

我想做的是,当从下拉列表中选择金融机构时,我想进行一个AJAX调用,将选择的FI与我的查询进行比较

当我尝试打印所选数据时,每次都会得到
None

这是我到目前为止所拥有的

edit.html javascript:

q = $("#investment_form").serialize();

function cdic_limit() {
        $.ajax({
        type: "POST",
        url: "{% url investments-calc_cdic plan.id %}",
        dataType: "json",
        data: q,
        success: function(json) {
            alert('made it here');
            }
        });
    }
在我的ajax.py中:

def calc_cdic(request, plan, *args, **kwargs):
    from investments.models import Investment
    from financial_institutions.models import FinancialInstitution
    from profiles.models import Profile
    from plans.models import Plan
    json = {}
    data = request.POST

    if request.is_ajax():
        print 'THIS IS THE PLAN: ', plan
        fiid = data.get('id_financial_institution')
        print 'THIS IS THE SELECTED FI:  ', fiid
        json['fiid'] = fiid

    return HttpResponse(simplejson.dumps(json), mimetype='application/json')
id\u financial\u institution
是我试图从中提取数据的表单上的字段名


任何帮助都将不胜感激。

我猜您得到的回复是403(禁止),您需要在视图中添加一个@csrf_豁免()

在Javascript代码中有一个变量
q
。这个变量的值是多少?顺便说一句,我想用$.post()替换$.ajax()。ajax函数中的
q
来自哪里?数据是什么:q?那个变量来自哪里?抱歉,q是一个复制粘贴错误。。。它用于从旧函数添加到查询字符串。如果可能(即,除非它是敏感的),请始终发布所有相关代码。不可避免地,你认为不重要的部分是其他人需要看到的,以便诊断你的问题。