1

I'm using smarty template and php. The following code is being written in smarty template.

{literal}
<script type="text/javascript">
// This function gets test when category checkbox is checked

function get_subjects_by_class(class_id) {
    var field_id = 'subjects';
    $.ajax({
        url: "teacher_details.php",
        type: "GET",
        data: {
            'request_type': 'ajax',
            'op': 'get_assigned_subject_list',
            'class_id': class_id
        },  
        success: function (data) {
            $('#category_test_container').append(data);
        });
    }
</script>
{/literal}

Call to this function is as follows :

<a href="#" onClick="get_subjects_by_class({$class.class_id}); return false;">{$class.class_name}</a>

Upon clicking on hyperlink I'm getting an error as follows :

ReferenceError: $ is not defined
$.ajax({

I googled it for the error resolution, but couldn't get the desired resolution. Can anyone help me out to resolve this error? Thanks in Advance.

4

3 回答 3

1

您要么没有加载 jQuery,要么在运行此脚本后加载了它。这就是$未定义的原因。

于 2013-05-21T10:53:22.297 回答
0

在 $ 变量可用之前,您需要首先包含 jQuery。$ 是 jQuery 的缩写,所以很明显 jQuery 不包含在 $.ajax 运行的地方。

于 2013-05-21T10:54:39.150 回答
0

页面中似乎不包含 jquery。请包含来自任何 CDN 的 jquery

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">
</script>

对于这种情况,也可能由于冲突而发生

http://api.jquery.com/jQuery.noConflict/

于 2013-05-21T10:55:15.517 回答