未捕获的引用错误;函数的定义尚未到来未定义 [英] Uncaught reference error; function is defined yet coming undefined

查看:991
本文介绍了未捕获的引用错误;函数的定义尚未到来未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是JavaScript函数,我写了

Here is the javascript function that I wrote

<script type="text/javascript">
function rate_prof(opcode, prof_id) {
    $.ajax({
        alert('Got an error dude');
        type: "POST",
            url: "/caller/",
            data: {
                mnemonics: opcode,
                prof_id: prof_id,
                csrfmiddlewaretoken: '{{ csrf_token }}'
            },
            success: function(data) {
                /*if(data!=="False"){
                    tempBool = false;
                    alert(data);
                    location.reload();
                }*/
            },
            failure: function(data) {
                alert('Got an error dude');
            },
            dataType: "html"
    });
}
</script>

现在由一个按钮调用该函数这种方式 -

Now on calling this function by a button this way-

<button class="btn btn-primary" value = "LIKE" onclick="rate_prof('LIKE',{{prof_rate.get_prof.get_username}})">Like</button>

我收到未捕获的Ref​​erenceError:rate_prof没有定义。在检查元素控制台

I am getting "Uncaught ReferenceError: rate_prof is not defined" in inspect element console.

单 - 功能正确定义和两个 - 页面的源$ C ​​$ C也显示了这种功能。所以,可能是什么问题?

One - the function is correctly defined and two - the source code of the page also shows this function. So what might be the problem?

我没有内部定义的功能,但可以很容易地做到这一点按钮调用函数之后。我是新的JavaScript,因此任何帮助将是AP preciated。

I have not defined functionality inside, but that can be done easily after that button calls the function. I am new in javascript so any help would be appreciated.

推荐答案

从参数在这里卸下警报:

Remove the alert from the argument here:

$.ajax({
   alert('Got an error dude'); // This line doesn't define an object property
   type: "POST",
   url: "/caller/",
          :
});

有一个语法错误,因为警告伤了你的code和功能将永远不会被定义。

A syntax error due to alert breaks your code, and the function will never be defined.

这篇关于未捕获的引用错误;函数的定义尚未到来未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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