-1

我正在尝试做一个 jquery ajax 教程,但我无法让它工作。

 $(document).ready(function () {
        //var theme = getDemoTheme();

        var url = "http://localhost/schoollife/services/getchapters.php?a=showdata";

        // prepare the data
        var source =
        {
            datatype: "json",
            datafields: [
                { name: 'curriculam_type', type: 'string' },
                { name: 'class_type', type: 'string' },
                { name: 'subject_type', type: 'int' },
                { name: 'chapter_name', type: 'string' },
                { name: 'chapter_number', type: 'int' },
                { name: 'author_name', type: 'string' },
                { name: 'reviewer_name', type: 'int' }                
            ],
            //id: 'id',
            url: url
        };
        var dataAdapter = new $.jqx.dataAdapter(source);

        $("#jqxgrid").jqxGrid(
        {
            width: 940,
            source: dataAdapter,
            //theme: theme,
            columnsresize: true,
            columns: [
              { text: 'Curriculum', datafield: 'curriculam_type', width: 100 },
              { text: 'Class', datafield: 'class_type', width: 100 },
              { text: 'Subjects', datafield: 'subject_type', width: 100 },
              { text: 'Chapter', datafield: 'chapter_name', width: 160 },
              { text: 'Chapter Number', datafield: 'chapter_number', cellsalign: 'center',width: 60},
              { text: 'Content Author', datafield: 'author_name'},
              { text: 'Content Reviewer', datafield: 'reviewer_name'},
               { text: 'Edit', datafield: 'Edit', width: 60, cellsrenderer: function () {
                 return '<div style="width:100%"><a href="edit_chapters.html", class="edit_chapters fancybox.iframe"><img src="../images/edit.png"  style="margin-left: 25%"/></a></div>';
             }, 
             },
                { text: 'Delete', datafield: 'delete', width: 60, cellsrenderer:function () {
                 return "<div style='width:100%'><a href='javascript:void(0)' class='**delbutton**'><img src='../Images/delete.png'  style='margin-left:25%'/></a></div>";
             }, 
             },

          ]
        });


 $(document).ready(function() {
    $(".**delbutton**").click(function(){ 
        alert('sdsdsd');

            alert('Are You sure you want to delete!');
             evt.preventDefault();
            var id=this.href;
            var url='http://localhost/schoollife/services/getchapters.php?a=deletechapter&chapter_id='+data[i].id;
            $.messager.confirm('Confirm','Are you sure you want to delete record?');
                $.ajax({
                    cache:false,
                    dataType:'json',
                    url:'http://localhost/schoollife/services/getchapters.php?a=deletechapter&chapter_id='+data[i].id,
                    async:false,
                    success:function(data){
                        alert(data);
                    }
                })

        });
    });
    });

如果我在 .js 文件中做同样的事情,我不会有任何问题。我在这里想念什么?谢谢

4

2 回答 2

0

您必须}); 在加载功能时关闭第一个文档。并考虑开括号和闭括号

于 2013-06-11T10:38:50.767 回答
0

那么,<script>标签呢:

<script>
  //js code here
</script>

您当然需要在包含 jquery 之后放置它。

于 2013-06-11T10:29:23.663 回答