3

我开发一个平台,使用 mvc + wcf + jquery + ajax ..

我英语不好所以我上传图片

在此处输入图像描述

这是 Ajax 响应

<script type='text/javascript'>
$(document).ready(function () {
    $('#{0}').flexigrid({
        url: 'GetDataList/',
        singleSelect: true,
        colModel: [{1}],
        searchitems: [{2}],
        sortorder: 'asc',
        usepager: true,
        title: '{3}',
        rp: 15,
        showTableToggleBtn: true
    });
    alert('{0} isimli grid load oldu');
});
</script>

我正确看到了警报消息,但插件有时无法加载

不仅对于 Flexigrid,所有 jquery 插件有时不加载有时加载..

编辑 1-

我认为无法从 ajax 初始化 jquery 请求

4

1 回答 1

1

如果我理解你的问题,这是我初始化 flexigrid 的方法

jQuery(document).ready(function() {
    jQuery("#invitedschoolstable").flexigrid({
                            url: 'index.php?option=com_users&task=profile.getinvitedschools&query='+id+'&format',//getSearchResults()
                            dataType: 'json',
                            colModel : [
                                {display: 'id', name : 'id', width : 40, sortable : true, align: 'center', hide: true},
                                {display: 'Σχολή', name : 'schoolname', width : 180, sortable : true, align: 'left', hide: false},
                                {display: 'Στοιχεία επικοινωνίας', name : 'stoixeiaepik', width : 250, sortable : false, align: 'left', hide: false},
                                {display: 'Κωδ.Σχολ', name : 'schoolid', width : 250, sortable : false, align: 'left', hide: true}
                                ],
                                sortname: "id",
                                sortorder: "asc",
                                usepager: true,
                                title: 'Λίστα προσκεκλημένων σχολών',
                                useRp: true,
                                rp: 10,
                                showTableToggleBtn: true,
                                width: 500,
                                nowrap: false,
                                height: 'auto',                         
                                onSuccess: invitedschoolstableSuccess,
                                qtype:'eventid',
                                query: id
                        }); 
});

这是通过 ajax 访问的后端 php 请注意,我在这里使用了一些室内 joomla 技巧来请求发布的值并对数据库进行查询,但没有太大区别。只需将它们替换为 php $_REQUEST 和经典的 mysql 命令即可访问数据库。所以不要盲目复制粘贴代码。

public function getinvitedschools(){
        $db = JFactory::getDBO();

            $page = 1; // The current page
            $sortname = 'id'; // Sort column
            $sortorder = 'asc'; // Sort order
            $qtype = ''; // Search column
            $query = ''; // Search string
            // Get posted data
                $jinput = JFactory::getApplication()->input;        
                $page = $jinput->get('page','','INT'); 

                //$eventid = $jinput->get('eventid','','INT');

                $sortname = $jinput->get('sortname','','STRING');

                $sortorder = $jinput->get('sortorder','','STRING');

                $qtype = $jinput->get('qtype','','STRING');

                $query = $jinput->get('query','','STRING');

                $rp = $jinput->get('rp');

            // Setup sort and search SQL using posted data
            $sortSql = ($sortname != '' && $sortorder != '') ? " order by $sortname $sortorder" : '';
            if (strpos($query, '%') !== false) {
                $searchSql = ($qtype != '' && $query != '') ? "where $qtype like '$query'" : '';
            }
            else 
            {
                $searchSql = ($qtype != '' && $query != '') ? "where $qtype = '$query'" : '';
            }

            if($searchSql=="")
             $searchSql.=" where d.dhmos=b.id and d.nomos=c.id and d.id=e.schoolid ";
            else
             $searchSql.=" and d.dhmos=b.id and d.nomos=c.id and d.id=e.schoolid  ";

            // Get total count of records
            $sql = "select count(*)
                    FROM #__Greekgeolocations b , 
                        #__Greekgeolocations c, 
                        #__fcse_fightclubs d    , 
                        #__fcse_eventsdiasil_schoollistselection e                  
            $searchSql";

            $db->setQuery($sql);
            $total = $db->loadResult();



            $pageStart = ($page-1)*$rp;
            $limitSql = "limit $pageStart, $rp";        
            $data = array();
            $data['page'] = $page;
            $data['total'] = $total;
            $data['rows'] = array();        
            $sql = "SELECT d.id,
                    b.locname as polhname,                       
                    c.locname as nomosname,         
                    d.address,      
                    d.name,
                    e.responsedate,
                    e.responseid                    
            FROM #__Greekgeolocations b , 
                #__Greekgeolocations c, 
                #__fcse_fightclubs d    , 
                #__fcse_eventsdiasil_schoollistselection e                         
            $searchSql              
            $sortSql
            $limitSql";

            //echo $sql;
            //die();
            $db->setQuery($sql);
            $results = $db->loadObjectList();

            foreach( $results as $row ){

                $today = new DateTime($row->thetimestamp);
                $today = $today->getTimestamp();

                 //$today = new DateTime('2013-03-21 17:30:00');
                 //$today = $today->getTimestamp();


                $data['rows'][] = array(
                        'id' => $row->id,
                        'cell' => array($row->id,                                       
                                        $row->name,
                                        $row->nomosname.' '.$row->polhname.' '.$row->address,
                                        $row->id
                                        ));
            }

            echo json_encode($data);    
    }

您可以将此代码添加到 jquery 就绪状态或任何其他事件,也可以使用 qtype 和 query 传递第一个初始化值。

如果您需要添加需要加载flexigrid 的代码,请使用 onSuccess: 并将一个方法与它挂钩,例如victedschoolstableSuccess 这实际上是在您的代码中定义的一个函数,例如函数invitationschoolstableSuccess(){} 'name it any you like' 所以你可以在那里执行你的代码。

此外,如果您稍后需要使用其他选项重新加载您的 flexigrid,您可以在单击事件或您希望这样的任何其他事件中使用以下代码

jQuery('#invitedschoolstable').flexOptions({ qtype:'school',query: 32 }).flexReload();

您还可以分配变量而不是像我所做的“学校”和 32 那样的固定值。

我希望这有帮助

于 2013-07-25T09:38:53.163 回答