dtsc14683 2013-04-17 15:59
浏览 22

使用具有不同AJAX源的DataTable,即UWA.Data.getJson

I'm trying to use DataTables with my work's Virtual Learning Environment.

Introduction

As I've mentioned in previous questions, our VLE uses the Netvibes Universal Widget API which allows me to write JavaScript files that can communicate both with the VLE (for retrieving information from the VLE's user accounts such as names and timetables) and, via proxy, an internal network webserver hosting PHP files and a database.

Netvibes UWA AJAX calls

So, for example, I can use this code to access my PHP scripts:

UWA.Data.getJson(List.URL + '?cmd=getObservations&filters=' + JSONdata, List.init);

Two simple parameters - url, callback.

Alternatively, I can use the full Data.request call:

UWA.Data.request(
    BookReviewInput.URL, 
    {
        method: 'post', 
        proxy: 'ajax', 
        type: 'json', 
        cache: 3600,
        parameters: obj,
        onComplete: BookReviewInput.process
    }

These scripts are written on our VLE, which has an internal network URL of http://vle.curriculum.local then an external URL of http://vle.ourschoolwebsite.com.

They communicate with scripts which are only accessible locally, from a URL of http://php.curriculum.local.

DataTables AJAX calls

I'm now trying to get DataTables to load information from my internally-located scripts, and I want it to do it all fully (i.e. pagination and everything) because we have a lot of data which is taking a lot of time to load in full.

First off, I made sure DataTables was working in the UWA format by manually copying some of the example tables off their website. The manual HTML table with the minimal .dataTable() functionality works correctly.

Then I tried to write the following code, which doesn't work:

<head>
    <script type="text/javascript">
    //<![CDATA[

    widget.onLoad = function(){
        $('#example').dataTable( {
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "http://php.curriculum.local/cmd.php"
        } );
    }

    //]]>
    </script>
</head>
<body>
    <div id="wrapper">
        <table cellpadding="0" cellspacing="0" border="0" class="display" id="example"> </table>
    </div>
</body>

The console error that I get from running this script is hideously uninformative, possibly because of the UWA wrapper:

Console error 1 When I click on 186642.js..

Console error 2

Server-side output

I know that the problem doesn't lie with the server side output, as I've validated it accordingly on http://pro.jsonlint.com:

{
    "sEcho": 0,
    "iTotalRecords": "5",
    "iTotalDisplayRecords": "5",
    "aaData": [
        [
            "2012-10-24",
            "35010",
            "34966",
            "10",
            "43",
            "2",
            "2",
            "2"
        ],
        [
            "2012-11-14",
            "34956",
            "35010",
            "10",
            "38",
            "2",
            "2",
            "2"
        ],
        [
            "2012-11-09",
            "90335",
            "34972",
            "11",
            "28",
            "2",
            "1",
            "1"
        ],
        [
            "2012-10-18",
            "34961",
            "34972",
            "11",
            "28",
            "2",
            "1",
            "2"
        ],
        [
            "2012-10-19",
            "34996",
            "34972",
            "11",
            "28",
            "2",
            "2",
            "2"
        ]
    ]
}

Probable cause

My relatively uninformed guess is that DataTables can't access my script because it's cross domain.

Problem is, there's no way I can put these scripts on the same domain - I don't have access to either PHP or MySQL on our VLE, nor does anyone in this organisation.

Potential solution

I think the answer is to try and use the UWA.Data calls within the DataTables function.

This is the UWA call I'd use to access my script: UWA.Data.getJson('http://php.curriculum.local/cmd.php' + '?cmd=getObservations', fnCallback);, though I presume I'd also need some way of sending dataTables' pagination variables etc. so I'd probably need to use the full UWA.Data.request call, and send a params object.

Sadly...

I have absolutely no idea if this is even possible, let alone how to do it.

Can anyone offer guidance?

Thanks in advance,

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据