1

ビューを作成しました

    $.getJSON("/admin/sync/sync_curl/4/whois",          
    function(data) {
        log("Who is onboard table has been updated with " + data + " records after " + modifiedSince);               
    });   

私のコントローラーでは、残りの呼び出しでリモートサーバーからjson文字列を取得する呼び出しを行い、ローカルデータベースを更新します-更新したレコードの数だけをビューに送り返します。

    function sync_curl($shipid, $table)  {  

        $this->load->model('whois/whois_m');

        $this->load->spark('curl/1.2.0');

        // Build remote URL            

        $remoteURL = 'http://192.201.00.22/api/1/';

        $remoteURL .= $table;

        $remoteURL .= '?API-KEY=xjkljioeo884444ssf'

        // Simple call to remote URL
        $result = json_decode($this->curl->simple_get($remoteURL), true);  

        // count records
        $count = 0;            
        foreach ($result[$table] as $record) {
            $this->whois_m->update_insert($record);            
            $count++;
        }

       header('Content-Type: application/x-json; charset=utf-8');
       echo $count;           
    } 

ブラウザーで $.getJSON = "local/admin/sync/sync_curl/4/whois"のビューで URL を直接使用すると、レコードの数を受け取ることができます。

ビューからこの関数を実行しようとすると-ボタンをクリックしてアクションを開始します-デバッグしても何も起こりません-このように「http://」を追加して$.getJSONリクエストを変更したとき

    $.getJSON("local/admin/sync/sync_curl/4/whois",    

私の質問は、なぜ「localhost」が必要なのですか? admin/sync/sync_curl/4/whoisだけが欲しいのですが、これを多くの異なるサーバーに展開する必要があり、リクエストは常にローカルですか?

4

1 に答える 1

0
$.getJSON("<?php echo site_url('admin/sync/sync_curl/4/whois'); ?>"
于 2012-11-17T20:11:25.853 に答える