简体   繁体   English

Javascript-未捕获的ReferenceError:函数未定义

[英]Javascript - Uncaught ReferenceError: function is not defined

I am relatively new at Javascript, and I have a page that calls a javascript function on onkeyup , but when called it throws an exception, Uncaught ReferenceError: validate is not defined . 我在Javascript方面相对较新,并且有一个页面在onkeyup上调用javascript函数,但是当该页面引发异常时, Uncaught ReferenceError: validate is not defined

<script type="text/javascript">
    function validate(id){
        alert(id);
        $.ajax({
            url: "http://example.com/restaurant/submit/verify",
            type: "POST",
            dataType: 'json',
            data: {
                field: id,
                content: $('#' + id).val()
            }
            success: function(data){
                alert(data);
                if(data.status == "PASSED"){
                    $('#' + id).removeClass('has-error');
                    $('#' + id).addClass('has-success');
                } else if(data.status == "FAILED") {
                    $('#' + id).removeClass('has-success');
                    $('#' + id).addClass('has-error');
                    $('#' + id + ' div').append('<span class="help-inline">' + data.error + '</span>')
                }
            }
        });
    }
</script>

Any help is greatly appreciated, if you need more info, don't hesitate to ask. 非常感谢您的帮助,如果您需要更多信息,请随时询问。 Thanks for any and all help. 感谢您提供的所有帮助。

You forgot a comma and a semicolon: 您忘记了逗号和分号:

    function validate(id){
    alert(id);
    $.ajax({
        url: "http://example.com/restaurant/submit/verify",
        type: "POST",
        dataType: 'json',
        data: {
            field: id,
            content: $('#' + id).val()
        }, // Here
        success: function(data){
            alert(data);
            if(data.status == "PASSED"){
                $('#' + id).removeClass('has-error');
                $('#' + id).addClass('has-success');
            } else if(data.status == "FAILED") {
                $('#' + id).removeClass('has-success');
                $('#' + id).addClass('has-error');
                $('#' + id + ' div').append('<span class="help-inline">' + data.error + '</span>'); // and here
            }
        }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM