在Codeigniator中获取Jquery JSON数据的问题

时间:2012-11-14 17:19:14

标签: jquery json codeigniter

我创建了一个视图

    $.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”,并且我会收到记录数。

当我尝试从我的视图中运行此功能时 - 我单击一个按钮开始操作 - 没有任何反应我已经调试,我没有 - 当我通过添加来更改$ .getJSON请求时,http: //“喜欢这个

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

我的问题是为什么我需要“localhost” - 我想要 admin / sync / sync_curl / 4 / whois - 因为我需要在许多不同的服务器上部署它,请求总是本地的?

1 个答案:

答案 0 :(得分:0)

$.getJSON("<?php echo site_url('admin/sync/sync_curl/4/whois'); ?>"