javascript函数没有被调用 [英] javascript function not getting called

查看:204
本文介绍了javascript函数没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django模板中,我有一个函数

In a Django template, I have a function

function show_graph(i){
    $("#"+i+"seegraph").click(function(){
        $("#"+i+"graph").show();

    var qaa = {{ question_ids }};

    var qid = qaa[i-1];
        jQuery.ajax({
            url: "/canvas/recreatechart/",
            type: "get",
            data: {qid: qid },
            success: function(response){
                var resp = jQuery.parseJSON(response);
                alert("chart1"+i);
                show_graph("chart1"+i, resp['chart_type'], resp['series_names'], JSON.stringify(resp['data1']), resp['answer'], resp['stories1'], resp['colors'], resp['stacked'], resp['title1']);

                show_graph(resp['second_graph']+i,resp['chart_type'], resp['series_names'], resp['data2'], resp['answer'], resp['stories2'], resp['colors'], resp['stacked'], resp['title2']);
            }

        });

    });
}

和show_graph内的一个警报,我从中推断出show_graph只是没有被调用,但我不知道为什么。

and an alert immediately inside show_graph, from which I've deduced that show_graph just isn't getting called, but I don't know why.

我的控制台没有任何错误,当我尝试在第一个呼叫中提醒每个参数一个接一个地显示出来,虽然data1显示为一个对象类型的object Object(当我对数据进行字符串化时,它出现在预期的状态,但是我不知道这是否意味着任何东西)。

I don't have any errors in my console, when I tried alerting each argument in the first call one by one, they all showed up as expected, although "data1" showed up as "object Object" with a type of "object" (When I stringified data1, it came out as expected, although I don't know if that means anything).

请注意,data1是一个字典数组,其数值是数组数组。所以,稍微复杂一些,我不知道js可以解析结构。

Note that data1 is an array of dictionaries, the values of which are arrays of arrays. So, slightly complicated, and I'm not sure if js can parse the structure.

这是为什么我的函数没有被调用?如果没有,那是什么?如果是这样,我该如何解决它(因为这是我必须传递我的数据的格式)。我如何找到问题?

Is that why my function is not getting called? If not, what is it? If so, how do I fix it (given that this is the format I have to pass my data in). How can I find the problem?

编辑:我也想注意,我刚刚测试了像[5]这样简单的代码data1,就像我这样害怕弄乱了函数调用,但是我仍然没有从show_graph获取警报,所以我认为这不是毕竟。

I would also like to note that I just tested something simple like [5] in place of data1, as that's what I was afraid was messing up the function call, but I'm still not getting the alert from show_graph, so I think that's not it after all.

推荐答案

你已经在一个名为 show_graph 的函数内。而不是调用所需的函数,它调用自己,并添加另一个单击操作...一个不匹配任何东西的jquery选择器。所以重命名你的内在功能,一切都应该起作用。

You're already inside of a function called show_graph. Instead of calling the function you want, it's calling itself, and adding another click action to...a jquery selector that doesn't match anything. So rename your inner function and everything should work.

这篇关于javascript函数没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆